Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the color of a disabled button in android

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> 
like image 316
nixgadget Avatar asked Oct 11 '15 23:10

nixgadget


People also ask

What is the color of disabled button?

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.

How can I change background color of clicking button in android?

Inside the function use setBackgroundResource(R. color. button_color) function, this will set the background with color button_color.

How do I change the default 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.

What is default color of button in android?

When I open a new android studio project, the default color for button is purple.


1 Answers

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> 
like image 125
AndroidEnthusiast Avatar answered Sep 18 '22 14:09

AndroidEnthusiast