How to change the color of a button?

后端 未结 8 1842
臣服心动
臣服心动 2021-02-03 20:08

I\'m new to android programming. How do I change the color of a button?

8条回答
  •  无人共我
    2021-02-03 20:34

    Here is my code, to make different colors on button, and Linear, Constraint and Scroll Layout

    First, you need to make a custom_button.xml on your drawable

    1. Go to res
    2. Expand it, right click on drawable
    3. New -> Drawable Resource File
    4. File Name : custom_button, Click OK

    Custom_Button.xml Code

    
    
         
         
         
    
    

    Second, go to res

    1. Expand values
    2. Double click on colors.xml
    3. Copy the code below

    Colors.xml Code

    
    
        #3F51B5
        #303F9F
        #FF4081
    
        #000
        #9400D3
        #4B0082
        #0000FF
        #00FF00
        #FFFF00
        #FF7F00
        #FF0000
    
    

    Screenshots below

    XML Coding Design Preview

提交回复
热议问题