我正在将我的应用升级到基于AppCompat v21的Android 5.0 Lollipop设计。
一切都运行得很好,但我遇到了首选项屏幕的问题,其中复选框不可见。它们在屏幕上,当整个部分被触摸时突出显示,我可以看到它们。功能很好,首选项也能成功更新。
应用程序复选框中的其他任何位置都显示没有任何问题。
此外,它在Android 2.3上也没有问题。
第2和第3设置中缺少复选框:
触摸行时可见复选框:
首选项及其代码非常基本,没有自定义添加。
带有首选项的我的xml文件如下所示(仅复制了复选框):
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:key="show_romaji"
android:title="@string/preferences_romaji_title"
android:summary="@string/preferences_romaji_explanation"
android:defaultValue="true"
android:persistent="true" />
<CheckBoxPreference
android:key="send_statistics"
android:title="@string/preferences_statistics_title"
android:summary="@string/preferences_statistics_explanation"
android:defaultValue="true"
android:persistent="true" />
</PreferenceScreen>
偏好设施活动:
public class PreferenceActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SharedPreferenceFragment())
.commit();
}
}
偏好片段:
public class SharedPreferenceFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
我正在使用几乎没有任何定义的主题:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.JlptVocabulary" parent="Theme.AppCompat">
<!-- Set AppCompat’s color theming attrs -->
<item name="colorPrimary">#ffe91e63</item>
<item name="colorPrimaryDark">@color/black</item>
<!-- The rest of your attributes -->
<item name="android:windowBackground">@color/backgroundBlack</item>
</style>
</resources>
我遇到了这个问题,经过一些研究和实验后仍无法找到解决方案。任何人都有线索?
答案 0 :(得分:0)
Theme.AppCompat样式的首选项中的复选框为黑色(框轮廓和填充除了复选标记)。复选标记采用首选项背景颜色。在您的情况下,您正在设置黑色背景,因此复选框不会显示,因为它们现在都是黑色的。我建议使用一个单独的样式(比如说:Theme.Pref_JlptVocabulary)来获得具有正常灰色背景的首选项,这样就会出现复选框。
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.Pref_JlptVocabulary" parent="Theme.AppCompat">
</style>
</resources>
另一种方法是通过重新定义复选框视图how-to-customize-the-color-of-the-checkmark-color-in-android...的样式来自定义复选框背景和复选标记颜色。
答案 1 :(得分:0)
您也可以尝试使用其中一个ThemeOverlays
<style name="SettingsTheme" parent="ThemeOverlay.AppCompat.Dark">
<item name="android:windowBackground">@color/backgroundBlack</item>
</style>
我发现这在黑色背景上给出了合适的复选框。但是,在Lollipop设备上(值-v21),我仍然使用常规主题扩展Theme.Appcompat,因为ThemeOverlay似乎覆盖了Lollipop手机上的'colorAccent'值
答案 2 :(得分:0)
我找到了另一个问题的解决方案。
这可能会导致,因为如果我们将 colorControlNormal 设置为与 style.xml 文件中 MyMaterialTheme.Base 主题中的应用程序背景颜色相同。
解决方案:更改应用程序默认背景颜色以外的colorControlNormal。