There is some inheritance problem with button borders. But I found a better way to do this. Let's say if you want to get the border only on the left side of the button. In the MainActivity XML file where the button is located, do it like this:
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/newstyle" android:orientation="vertical" > <Button android:id="@+id/button3" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@null" android:gravity="center_vertical" android:paddingLeft="10sp" android:text="Button" android:textAllCaps="false" android:textColor="#939393" android:textSize="20sp" /> </LinearLayout>
For the newstyle.xml file to be located in drawable, use this code -
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:bottom="0sp" android:left="-2sp" android:right="-2sp" android:top="-2sp"> <shape android:shape="rectangle" > <solid android:color="#ffffff" /> <stroke android:width="1sp" android:color="#d6d6d6" /> </shape> </item> </layer-list>
So the whole idea is - Keep the button background as @null and keep the button in the linera layout. Give the background to the layout of the liner and make it again .. :) ..
source share