android – Set a border in corners of layout-ThrowExceptions

Exception or error:

I want to add border like the one in the image below. I tried achieve this using xml drawables’ layer-list component, but I couldn’t.

How to solve:

create new drawable resource file into the drawable folder and add below code

<shape xmlns:android=""

    <solid android:color="#FFFFFF" />
   <corners android:radius="@dimen/_10sdp"

and set this drawable as the background of your parent layout


Create an XML file named border.xml in the drawable folder and put the following code in it.

 <?xml version="1.0" encoding="utf-8"?>
 <layer-list xmlns:android="">
    <shape android:shape="rectangle">
      <solid android:color="#FF0000" /> 
    <item android:left="5dp" android:right="5dp"  android:top="5dp" >  
     <shape android:shape="rectangle"> 
      <solid android:color="#000000" />

Then add a background to your linear layout like this:


Finally its works perfectly with all APIs

Let me know if it was usefull Behzad Fartash

Leave a Reply

Your email address will not be published. Required fields are marked *