这就是我为节省drawables的价值而做的事情:
case R.id.purple:
for (Button currentButton : buttons) {
currentButton.setBackgroundResource(R.drawable.purple);
button1 = buttoncos = buttonmadd = R.drawable.purple;
}
editor.putInt("DigitButtonStyle",button1);
editor.putInt("MemoryButtonStyle", buttonmadd);
editor.putInt("FunctionButtonStyle", buttoncos);
editor.commit();
return true;
这里的Drawable是integeral值,所以很容易。我如何存储不同主题的值。
答案 0 :(得分:0)
简单的方法是 SharedPreferences
保存相关值:
SharedPreferences shared=getSharedPreferences("theme", Activity.MODE_PRIVATE);
shared.edit().putString("theme_name", "THEME_BLUE").commit();
检索保存的数据:
SharedPreferences shared=getSharedPreferences("theme", Activity.MODE_PRIVATE);
String theme=shared.getString("theme_name", null);
了解更多信息:link
答案 1 :(得分:-1)
在此页面中阅读此setTheme,它告诉您不能在活动中使用,换句话说,必须在为您的活动设置任何主题之前完成。