Lollipop: Disabled button –> which style?

I tried to track down, how Lollipop displays a button, which is disabled with android:enabled="false" in the layout file.

Holo

With Holo, it’s easy: In the styles_holo.xml, I find the style Widget.Holo.Button, which gives me a reference to @drawable/btn_default_holo_dark. There I find the selector:

  • Select multiple images from android gallery
  • OpenGL ES 2.0 vs OpenGL 3 - Similarities and Differences
  • Precise metronome for android
  • File Chooser not works in Samsung Tab 3 Android 4.4
  • Delete system cache on android 6.0
  • android app that accesses the sim toolkit
  • <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_window_focused="false" android:state_enabled="true"
    android:drawable="@drawable/btn_default_normal_holo_dark" />
    <item android:state_window_focused="false" android:state_enabled="false"
    android:drawable="@drawable/btn_default_disabled_holo_dark" />
    <item android:state_pressed="true"
    android:drawable="@drawable/btn_default_pressed_holo_dark" />
    <item android:state_focused="true" android:state_enabled="true"
    android:drawable="@drawable/btn_default_focused_holo_dark" />
    <item android:state_enabled="true"
    android:drawable="@drawable/btn_default_normal_holo_dark" />
    <item android:state_focused="true"
    android:drawable="@drawable/btn_default_disabled_focused_holo_dark" />
    <item
    android:drawable="@drawable/btn_default_disabled_holo_dark" />
    </selector>
    

    Lollipop

    When I try to apply the same logic to Lollipop, I got stuck:

    In styles_material.xml I find the style <style name="Widget.Material.Button"> where I find the reference to <item name="background">@drawable/btn_default_material</item>. But there is no selector??!! Instead I find:

    <ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?attr/colorControlHighlight">
    <item android:drawable="@drawable/btn_default_mtrl_shape" />
    </ripple>
    

    Could someone please explain, which specific style Lollipop uses for a disabled button.
    Thanks a lot!

    Edit

    I can partially answer myself: In @drawable/btn_default_mtrl_shape I find a reference to <solid android:color="?attr/colorButtonNormal" />, which in turn points to @color/btn_default_material_light, which includes a selector:

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false"
    android:alpha="@dimen/disabled_alpha_material_light"
    android:color="@color/button_material_light"/>
    <item android:color="@color/button_material_light"/>
    </selector>
    

    But that alpha value only explains half of it. Somehow Lollipop also set the elevation down to 0?

    Related posts:

    Is it possible to load a drawable from the assets folder?
    Android: How do I get GSM signal strength for all available network operators
    Popup DatePicker for EditText
    Why are these permissions being refused?
    Google&#039;s Json Parsing Gson library: What&#039;s the difference between JsonElement and ...
    Tools for rapid layout/interface creations?
  • EditText added is not a TextInputEditText. Please switch to using that class instead
  • Text leftside of a RadioButton with a margin on Android
  • Is it possible to run Android Device Emulator (via Android Studio 2) on VMWare?
  • Different height for each item in GridView
  • android turning on wifi programmatically
  • Drawing rotated bitmap with anti alias
  • One Solution collect form web for “Lollipop: Disabled button –> which style?”

    This is how I resolved this, thanks to your partially answer.

    First: add new Folder “color” under “res” folder, if it doesn`t exist.enter image description here

    Add new .xml file in “color” folder (I will call this file ButtonColorSelector.xml) where we will create new ColorStateList like this:

    <?xml version="1.0" encoding="UTF-8" ?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_enabled="false" android:color="#F2F2F2"/> <!-- disabled -->
        <item android:state_pressed="true" android:color="#FF0000"/> <!-- pressed -->
        <item android:state_focused="true" android:color="#FF0000"/> <!-- focused -->
        <item android:color="#0000FF"/> <!-- default -->
    </selector>
    

    Second: Add that ripple effect .xml file you mentioned, under “drawable” folder and reference your colorSelector instead of btn_default_mtrl_shape. I will call this file RaisedButton.xml.

    <?xml version="1.0" encoding="utf-8"?>
    <ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="?attr/colorControlHighlight">
        <item>
            <shape>
                <solid android:color="@color/buttoncolorselector"/>
                <corners android:radius="5dp" />
            </shape>
        </item>
    </ripple>
    

    Third: Now you can use your drawable for button background in your layouts, like this:

    <Button
        android:background="@drawable/raisedbutton"
        android:text="@string/SomeButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="DoStuffitto"
        android:enabled="false"
        android:id="@+id/someButton" />
    
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.