android set button background programmatically

前端 未结 8 743
天涯浪人
天涯浪人 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:29

    You can set your desired color to the button programmatically like:

    Button11.setBackgroundColor(Android.Graphics.Color.parseColor("#738b28"));
    

    Also you can give the text color for a button like:

    Button11.setTextColor(Android.Graphics.Color.parseColor("#FFFFFF"));
    

提交回复
热议问题