Android 使用颜色数值更改按钮的颜色

Android 使用颜色数值更改按钮的颜色,android,colors,Android,Colors,我通过以下方式更改按钮的颜色: final Button BB1 = (Button)findViewById(R.id.button3); BB1.setBackgroundColor(Color.RED); 我怎样才能换成颜色呢?试试这个 final Button BB1 = (Button)findViewById(R.id.button3); BB1.setBackgroundColor(Color.parseColor("#FF6600")); 对于微

我通过以下方式更改按钮的颜色:

final Button BB1 = (Button)findViewById(R.id.button3);
               BB1.setBackgroundColor(Color.RED);
我怎样才能换成颜色呢?

试试这个

final Button BB1 = (Button)findViewById(R.id.button3);
BB1.setBackgroundColor(Color.parseColor("#FF6600"));
对于微调器选择


您是否尝试过
spinner.setSelection(14)?(14或15,在开始时通过您需要的索引)

您必须按以下方式使用

BB1.setBackgroundColor(Color.rgb(0xff, 0x66, 0x00));
一种更为“关注点分离”的解决方案是将颜色添加到strings.xml

<color name="button_background">#f60</color>
如果有更多相同颜色的小部件,这个解决方案就更有意义了


BTW,考虑使用CAMEL案例命名变量,即命名按钮对象BB1(或BB1,如果必须:)-而不是BB1。

请在每个帖子中问一个问题。对于第二个不相关的问题,请另问一个问题。
BB1.setBackgroundColor(R.color.button_background);