【发布时间】:2015-05-14 08:49:13
【问题描述】:
您好,我在 styles.xml 中有四个自定义样式,我正在尝试使用 RadioGroup 来选择整个应用程序的整体样式。
<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 选择的代码,我之前曾尝试使用 CheckBoxes 进行此操作,这就是名称都是复选框的原因。
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 没有当前在我的所有应用活动中显示的颜色。 由于某种原因,正在显示的主题具有灰色文本和深灰色/黑色背景,唯一正确显示的颜色是我在每个单独的 layout/activity_myActiviitesThatHaveButtons xml 文件中手动设置的按钮的背景颜色。我不确定我做错了什么,任何人都可以尝试提供一些帮助吗?谢谢你的帮助
P.S:不确定这是否重要,但我相信我的 min API 设置为 8,我相信这就是我的教授想要的设置。
【问题讨论】:
标签: android styles radio-button themes