android set button background programmatically

前端 未结 8 755
天涯浪人
天涯浪人 2020-11-30 02:57

I would like to know how to set the button color programatically? I have coded the following but fails:

Button11.setBackgroundColor(R.color.red);
         


        
8条回答
  •  广开言路
    2020-11-30 03:44

    button.setBackgroundColor(getResources().getColor(R.color.red);
    

    Sets the background color for this view. Parameters: color the color of the background

    R.color.red is a reference generated at the compilation in gen.

提交回复
热议问题