在每个项目点击时,提到的它们应该应用于应用程序。
但是当我在手机中运行该应用程序并选择一个选项时,主题没有改变,并且 toast 也没有显示。
没有错误出现,应用也没有崩溃。它只是不起作用。
而且我愿意通过微调器来完成此操作。我该怎么办?
这是我的代码:
final ListView themeList = (ListView) findViewById(R.id.themeList);
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position == 0) {
getApplicaiton().setTheme(R.style.themeOne);
} else if (position == 1) {
getApplicaiton().setTheme(R.style.themeTwo);
} else if (position == 2) {
getApplicaiton().setTheme(R.style.themeThree);
} else {
Toast.makeText(ThemeActivity.this, "Something went wrong, please try again!", Toast.LENGTH_SHORT).show();
}
};
最佳答案
根据 setTheme 的 Android 网站文档
Set the base theme for this context. Note that this should be called before any views are instantiated in the Context (for example before calling setContentView(View) or inflate(int, ViewGroup)).
因此您需要在此之前进行更改。
关于java - 如何通过从 ListView 或 android 中的微调器中选择选项来更改应用程序主题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46469747/