I'm in the process of upgrading my app to Android 5.0 Lollipop design based on AppCompat v21.
Everything works fairly well but I hit a problem with the preferences screen where checkboxes are not visible. They are on the screen and I can see them when the whole section gets highlighted when it's touched. Functionality is fine and preferences are updated successfully.
Everywhere else in the app checkboxes display without any problems.
Also, it works without a problem on Android 2.3.
Checkboxes missing in the 2nd and 3rd setting:
Checkbox visible when touching the row:
Preferences and the code for them is very basic and has nothing custom added.
My xml file with preferences looks like this (only checkboxes copied):
<?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>
Preferences activity:
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();
}
}
Preferences fragment:
public class SharedPreferenceFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
I'm using a theme which has almost nothing defined as well:
<?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>
I'm stuck with this problem and haven't been able to find a solution after doing some research and experiments. Anyone has a clue?
The checkboxes in preferences for Theme.AppCompat style are black (box outline and fill except for the check mark). The check mark takes color of preferences background. In your case, you are setting black background, so checkboxes do not show since they are now all black. I suggest using a separate style (say: Theme.Pref_JlptVocabulary) for the preferences with its normal grayish background so checkboxes appear.
<?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>
The other way would be to customize the checkboxes background and check mark colors by redefining the style for checkbox views how-to-customize-the-color-of-the-checkmark-color-in-android....