I am trying to use setEnabled(false) on a Button to show grey disabled state...
I can only get the desired result if I force a theme on the button with
android:theme="@style/Button"and then change the parent on that Button style to something other than the
Theme.AppCompat.Light.DarkActionBar, such as from Material:<style name="Button" parent="android:Theme.Material.Light.NoActionBar">(even then, only the button background changes, the text color doesn't.)
I can't see the Button as grey when set disabled if I leave the Button to take the defaults. (My understanding is that when using
Theme.AppCompat.,ButtonbecomesAppCompat.Widget.Buttonand inherits aColorStateList.)
In my res\values\styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<!-- only way I could get this to work -->
<style name="Button" parent="android:Theme.Material.Light.NoActionBar">
<!--<item name="colorAccent">@color/butt</item>-->
<!--<item name="colorButtonNormal">@color/butt</item>-->
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
In AndroidManifest.xml
<application
android:theme="@style/AppTheme"
( and nothing under <activity> )
My MainActivity extends Activity
- but I have also tried extends
AppCompatActivityand had the same problem.
So what is going on here? Why doesn't the default work for a "disabled button"?
- (And if I do inherit from
Materialtheme (as above), why does the Button text color not change? Basically, why don't the Buttons look like they do in the theme editor?)
Also
when I specify a custom
ColorStateListviares\color, why can't I override just some of the states? I tried to have only<item android:state_enabled="false" android:color="#616161" />But it didn't work. I was only able to get a greyed disable Button using this method if I specified more
<item>s, even though I don't care to match other states. It only works If I add something like:<!-- disabled state --> <item android:state_enabled="false" android:color="#616161" /> <!-- enabled state --> <item android:state_enabled="true" android:color="@color/colorPrimaryLighter" /> <!-- default --> <item android:color="#ffffff"/>
My supportLibraryVersion = '27.1.1'
I have already seen
How to setup disabled color of button with AppCompat?
Widget.AppCompat.Button colorButtonNormal shows gray
State list drawable and disabled state
Android - default button style
Android: change color of disabled text using Theme/Style?
When should one use Theme.AppCompat vs ThemeOverlay.AppCompat?
I don't want to override the defaults if I don't have to and specify anything I don't have to. Thanks in advance!

