Create an XML called border.xml in the folder with the extension as shown below:
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <solid android:color="#FF0000" /> </shape> </item> <item android:left="5dp" android:right="5dp" android:top="5dp" > <shape android:shape="rectangle"> <solid android:color="#000000" /> </shape> </item> </layer-list>
then add this to the linear layout as a backgound like this:
android:background="@drawable/border"
Program
TitleLayout.setBackgroundDrawable(getResources().getDrawable(R.drawable.border))
EDIT:
Since Jelly Bean, this method (setBackgroundDrawable is deprecated), so you should use it:
TitleLayout.setBackground(getResources().getDrawable(R.drawable.border));
hope this help.
source share