How to style PreferenceFragmentCompat

混江龙づ霸主 提交于 2019-11-27 02:21:49

问题


I'm using a PreferenceFragmentCompat, but I don't think it is styled correctly.

Preferences' title seems way to big, PreferenceCategory text is unreadable, the whole think seems off.

This is what I have in theme.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    ...
    <item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
</style>

<style name="PreferenceThemeOverlay">
    <item name="preferenceScreenStyle">@style/Preference.PreferenceScreen</item>
    <item name="preferenceFragmentStyle">@style/PreferenceFragment</item>
    <item name="preferenceCategoryStyle">@style/Preference.Category</item>
    <item name="preferenceStyle">@style/Preference</item>
    <item name="preferenceInformationStyle">@style/Preference.Information</item>
    <item name="checkBoxPreferenceStyle">@style/Preference.CheckBoxPreference</item>
    <item name="switchPreferenceCompatStyle">@style/Preference.SwitchPreferenceCompat</item>
    <item name="dialogPreferenceStyle">@style/Preference.DialogPreference</item>
    <item name="editTextPreferenceStyle">@style/Preference.DialogPreference.EditTextPreference
    </item>
    <item name="preferenceFragmentListStyle">@style/PreferenceFragmentList</item>
</style>

回答1:


Following this.

Change

<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>

to

<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>

Then, change in build.gradle dependencies

com.android.support:preference-v7

to

com.android.support:preference-v14


来源:https://stackoverflow.com/questions/34220035/how-to-style-preferencefragmentcompat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!