Is there a way to change the color of a disabled button in android through styles or some other form ?
I currently have the following,
drawable/button_default.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/button_default_shape"/> </selector>
drawable/button_default_shape.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@color/button_default_background"/> <corners android:radius="3dp"/> </shape>
values/styles.xml
<style name="AppTheme.Button"> <item name="android:background">@drawable/button_default</item> <item name="android:textColor">@android:color/white</item> <item name="android:textAllCaps">false</item> <item name="android:paddingTop">10dp</item> <item name="android:paddingBottom">10dp</item> <item name="android:focusable">true</item> <item name="android:clickable">true</item> <item name="android:gravity">center</item> <item name="android:textStyle">bold</item> <item name="android:textSize">17sp</item> <item name="android:textAppearance">@style/CustomFontAppearance</item> </style>
Gray is often used to communicate a low priority button (e.g., cancel buttons). When they see a gray button, they won't know for sure if it's disabled unless they click it.
Inside the function use setBackgroundResource(R. color. button_color) function, this will set the background with color button_color.
Android Colored Buttons The Colored Button takes the color of the colorAccent attribute from the styles. xml file. Change the color of colorAccent to one of your choice to get the desired background color. Now, there are two important attributes to style a button : colorButtonNormal : The normal color of the button.
When I open a new android studio project, the default color for button is purple.
You'll have to use a selector for different drawables in those states.
You can create a selector like this:
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/your_enabled_drawable" android:state_enabled="true" /> <item android:drawable="@drawable/your_disabled_drawable" android:state_enabled="false" /> <!-- default state--> <item android:drawable="@drawable/your_enabled_drawable" /> </selector>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With