Change the color of a disabled button in android

后端 未结 6 1366
灰色年华
灰色年华 2021-02-03 22:56

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_de

6条回答
  •  猫巷女王i
    2021-02-03 23:31

    UPDATE: For Android MaterialButton

    For Android MaterialButton there are two solutions, one for SDK >= v21 and another for SDK < v21.

    Here I am also giving how to change the text color of the button depending whether it is enabled or disabled.

    First create two color selector .xml file in your color folder. One for button color and another for button text color. For example button_state_colors.xml for button color and button_text_state_colors.xml for text color.

    Here are those two color files:

    1. button_state_colors.xml:

       
       
           
           
       
      
    2. button_text_state_colors.xml:

       
       
           
           
       
      

    Now for all versions of Android SDK you can change the color of button and it's text using style like:

    in style.xml:

    
    

    in layout.xml:

    
    

    Only for SDK >= 21 you can direct change button color without using style like:

    
    

提交回复
热议问题