Android Button Frame Color

I am creating an Android Button using the following XML.

The output on the Preview of Design is shown below. enter image description here

However, when I launch the device, Samsung Duos. This shows a completely different. enter image description here

How to set the border.

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <stroke android:width="3dp" android:color="#d78d79" /> </shape> 

I also get an error in XML, but it works fine. Nothing is displayed when the mouse hovers over an error.

enter image description here

Can anyone help?

+5
source share
2 answers

Add <solid android:color="@android:color/transparent" /> as a child of the shape element

 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <solid android:color="@android:color/transparent" /> <stroke android:width="3dp" android:color="#d78d79" /> </shape> 
+9
source

I usually do something like that!

You can do all this in one XML, but I will show you a long way so you can better understand.

simple_button.xml

 <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/button_pressed"/> <item android:state_enabled="false" android:drawable="@drawable/button_disabled"/> <item android:state_enabled="true" android:drawable="@drawable/button_enabled"/> </selector> 

button_pressed.xml

 <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="2dp" /> <solid android:color="#20FF5252" /> <padding android:bottom="0dp" android:left="0dp" android:right="0dp" android:top="0dp" /> <size android:width="100dp" android:height="35dp" /> <stroke android:width="1dp" android:color="#1DE9B6" /> </shape> 

button_disabled.xml

 <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <corners android:radius="14dp" /> <solid android:color="@android:color/transparent" /> <padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" /> <stroke android:width="8dp" android:color="#1DE9B6" /> </shape> 

button_enabled.xml

  <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <corners android:radius="2dp" /> <solid android:color="@android:color/transparent" /> <padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" /> <size android:width="260dp" android:height="50dp" /> <stroke android:width="1dp" android:color="#1DE9B6" /> </shape> 

styles.xml

  <style name="Widget.Button.Simple" parent="android:Widget"> <item name="android:gravity">center_vertical|center_horizontal</item> <item name="android:background">@drawable/simple_button</item> <item name="android:textAppearance">?android:textAppearanceMedium</item> <item name="android:textColor">#1DE9B6</item> <item name="android:textStyle">bold</item> </style> 

Using

  <Button android:id="@+id/btn_simple" style="@style/Widget.Button.Simple" android:layout_width="match_parent" android:layout_height="50dp" android:layout_margin="20dp" android:text="Button" /> 

Hope this helps!

+6
source

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


All Articles