How to change the color of a button?

后端 未结 8 1826
臣服心动
臣服心动 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:32

    You can change the colour two ways; through XML or through coding. I would recommend XML since it's easier to follow for beginners.

    XML:

    You can also use hex values ex.

    android:background="@android:color/white"
    

    Coding:

    //btn represents your button object
    
    btn.setBackgroundColor(Color.WHITE);
    btn.setTextColor(Color.BLACK);
    

提交回复
热议问题