Hello我在styles.xml中有四个自定义的样式,我尝试使用RadioGroup来选择整个应用程序的总体样式。使用RadioButtons更改整个Android应用程序的主题
<style name="blueTheme" parent="android:Theme.Light.NoTitleBar.Fullscreen">
<item name="android:windowBackground">@color/blue_background</item>
<item name="android:textColorPrimary">@color/blue_text</item>
</style>
<style name="redTheme" parent="android:Theme.Light.NoTitleBar.Fullscreen">
<item name="android:windowBackground">@color/red_background</item>
<item name="android:textColorPrimary">@color/red_text</item>
</style>
<style name="greenTheme" parent="android:Theme.Light.NoTitleBar.Fullscreen">
<item name="android:windowBackground">@color/green_background</item>
<item name="android:textColorPrimary">@color/green_text</item>
</style>
<style name="bwTheme" parent="android:Theme.Light.NoTitleBar.Fullscreen">
<item name="android:windowBackground">@color/bw_background</item>
<item name="android:textColorPrimary">@color/bw_text</item>
</style>
这里是我的实际的RadioGroup中选择的处理的代码,我以前用的CheckBox尝试这个,这就是为什么名称是所有复选框。
blueCheckBox = (RadioButton) findViewById(R.id.blueCheckBox);
redCheckBox = (RadioButton) findViewById(R.id.redCheckBox);
greenCheckBox = (RadioButton) findViewById(R.id.greenCheckBox);
bwCheckBox = (RadioButton) findViewById(R.id.bwCheckBox);
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.themeRadioGroup);
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// checkedId is the RadioButton selected
switch(checkedId) {
case R.id.blueCheckBox:
getApplication().setTheme(R.style.blueTheme);
break;
case R.id.redCheckBox:
getApplication().setTheme(R.style.redTheme);
break;
case R.id.greenCheckBox:
getApplication().setTheme(R.style.greenTheme);
break;
case R.id.bwCheckBox:
getApplication().setTheme(R.style.bwTheme);
break;
}
}
});
我遇到的问题是整体风格根本不会改变。在我的AndroidManifest.xml文件中,我默认我的主题为
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/blueTheme" >
但尽管如此,当我运行我的应用程序主题不是blueTheme。 blueTheme没有当前所有应用程序的活动显示的颜色。 由于某些原因,显示的主题具有灰色文本和深灰色/黑色背景,正确显示的唯一颜色是我在各个布局/ activity_myActiviitesThatHaveButtons xml文件中手动设置的按钮的背景颜色。我不确定我做错了什么,任何人都可以请尝试提供一些帮助?感谢您的帮助
P.S:不知道这个问题是否重要,但我相信我的min API设置为8,我相信这是我的教授所希望的。