【发布时间】:2020-11-12 04:35:19
【问题描述】:
刚开始在 Android Studio 中工作,对于大多数事情,我可以用“Google it”找到一切都很好,但显然对于这件事我没有。我有一个基本的开关按钮,我想将应用程序颜色背景从白色更改为黑色,然后取消选中该按钮。询问非常简单,将开关的文本从“黑暗模式”更改为“白色模式”就可以了。 询问在 MainActivity.java 中完成。
final Switch BackgroundColorButton = (Switch) findViewById(R.id.BackgroundColorButton);
BackgroundColorButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(BackgroundColorButton.isChecked())
{
BackgroundColorButton.setText("White Mode");
//here I need to change the app background color to Black or DarkGray
}
else
{
BackgroundColorButton.setText("Dark Mode");
//here I need to change the app background color to White
}
}
});
【问题讨论】:
标签: java android android-studio