单击一下即可自定义 android 应用的整个主题
Customize the entire theme of android app on a single click
我想通过单击按钮更改我的应用程序的整个主题(包括工具栏颜色、背景颜色和字体)。谁能建议如何以编程方式执行此操作?
是的,你可以做到,事实上它非常棒:我最近做到了
你只需要了解 android 的 settheme() 方法:
所以让我先描述一下整个场景:
首先,您需要在 style.xml
中添加不同的主题
2>现在在共享首选项中按如下方式添加和映射这些主题:
SharedPreferences pref = PreferenceManager
.getDefaultSharedPreferences(this);
String themeName = pref.getString("prefSyncFrequency3", "Theme1");
if (themeName.equals("Africa")) {
setTheme(R.style.AppTheme);
} else if (themeName.equals("Colorful Beach")) {
//Toast.makeText(this, "set theme", Toast.LENGTH_SHORT).show();
setTheme(R.style.beach);
} else if (themeName.equals("Abstract")) {
//Toast.makeText(this, "set theme", Toast.LENGTH_SHORT).show();
setTheme(R.style.abstract2);
} 否则如果 (themeName.equals("Default")) {
setTheme(R.style.defaulttheme);
}
现在点击你可以有条件语句,你可以从共享首选项中获取主题:
有关详细信息,请参阅此 link
如果有帮助请告诉我:)
我想通过单击按钮更改我的应用程序的整个主题(包括工具栏颜色、背景颜色和字体)。谁能建议如何以编程方式执行此操作?
是的,你可以做到,事实上它非常棒:我最近做到了 你只需要了解 android 的 settheme() 方法:
所以让我先描述一下整个场景: 首先,您需要在 style.xml
中添加不同的主题2>现在在共享首选项中按如下方式添加和映射这些主题:
SharedPreferences pref = PreferenceManager
.getDefaultSharedPreferences(this);
String themeName = pref.getString("prefSyncFrequency3", "Theme1");
if (themeName.equals("Africa")) {
setTheme(R.style.AppTheme);
} else if (themeName.equals("Colorful Beach")) {
//Toast.makeText(this, "set theme", Toast.LENGTH_SHORT).show();
setTheme(R.style.beach);
} else if (themeName.equals("Abstract")) {
//Toast.makeText(this, "set theme", Toast.LENGTH_SHORT).show();
setTheme(R.style.abstract2);
} 否则如果 (themeName.equals("Default")) {
setTheme(R.style.defaulttheme);
}
现在点击你可以有条件语句,你可以从共享首选项中获取主题:
有关详细信息,请参阅此 link
如果有帮助请告诉我:)