我已经在谷歌搜索了很多,并在本网站广泛也,如果我错过了回答我的问题,我很抱歉。但这里有云:Android布局背景颜色变化
public void onClick(View v){
Button btt= (Button) findViewById(R.id.bttROnOff);
LinearLayout ll = (LinearLayout) findViewById(R.id.layScreen);
if ((btt.getText()).toString().compareToIgnoreCase("Reading Mode OFF")==0) {
ll.setBackgroundColor(R.color.paleYellow);
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = originalBrightness;
getWindow().setAttributes(lp);
btt.setText("Reading Mode ON");
}
else {
ll.setBackgroundColor(Color.WHITE);
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 1;
getWindow().setAttributes(lp);
btt.setText("Reading Mode OFF");
}
}
我有一个按钮来改变背景颜色为白色,然后以“浅黄色”,这是在strings.xml档案中定义。在我的XML布局文件中,它以这种颜色开始,当我按下它时,它变成白色。但如果我按下按钮返回到前一个,我得到的是黑色背景。如果我改用:
ll.setBackgroundColor(Color.Yellow);
它的工作原理,但:
ll.setBackgroundColor(R.color.paleYellow);
不:S
非常感谢...需要多加关注:) –