The border is only on the left side of the button

Here is my button_style.xml, which I enable using my button. However, I still cannot get the border on the left. Can someone help me here please?

ps - My background should be transparent

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <layer-list> <item android:left="2dp"> <shape android:shape="rectangle"> <stroke android:width="1dp" android:color="#999999"/> </shape> </item> </layer-list> </selector> 
+4
source share
4 answers

try it

 <?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="@android:color/transparent" /> </shape> </item> <item android:bottom="-2dp" android:right="-2dp" android:top="-2dp"> <shape> <solid android:color="@android:color/transparent" /> <stroke android:width="2dp" android:color="#FFF" /> </shape> </item> </layer-list> 
+9
source

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 .. :) ..

+2
source
  <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <layer-list> <item android:left="2dp" android:right="0dp" android:top="0dp" android:bottom="0dp" > <shape android:shape="rectangle"> <stroke android:width="1dp" android:color="#999999"/> </shape> </item> </layer-list> </selector> 

try this it can work

0
source

try it

 <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape> <padding android:left="1dp" /> <solid android:color="#999999" /> </shape> </item> <item> <shape android:shape="rectangle"> <solid android:color="@android:color/transparent" /> </shape> </item> </layer-list> 
0
source

Source: https://habr.com/ru/post/1468901/


All Articles