How to change the color of a button?

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

    If you are trying to set the background as some other resource file in your drawable folder, say, a custom-button.xml, then try this:

    button_name.setBackgroundResource(R.drawable.custom_button_file_name);
    

    eg. Say, you have a custom-button.xml file. Then,

    button_name.setBackgroundResource(R.drawable.custom_button);
    

    Will set the button background as the custom-button.xml file.

提交回复
热议问题