Android: change button background programmatically

前端 未结 3 930
醉酒成梦
醉酒成梦 2021-01-14 00:47

I have this resource file for colors


    #00f
    #f00         


        
3条回答
  •  甜味超标
    2021-01-14 01:17

    setBackgroundResource is expecting a drawable, not a color. You want setBackgroundColor.

    Also, your colors should have at least 6 digits, #RRGGBB

    I.e., for blue: #0000FF

    I think what you have might be equivalent to #00000F, which is close to black...

    And finally, you should never sleep in the UI thread (or change UI items not in the UI thread). See Painless Threading for a number of different ways of using other threads. I think that postDelayed might be what you are looking for.

提交回复
热议问题