I want to set title style for my preference fragment screen V14.
This is what I want:
I have followed
Custom PreferenceCategory Headings
I did manage to get the same screen but with PreferenceFragment!!
How can I do it for PreferenceFragmentCompat V14??
Here is my Code
Style.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:listSeparatorTextViewStyle">@style/PreferenceStyle</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
</style>
<style name="PreferenceStyle" parent="@android:style/Widget.TextView">
<item name="android:textColor">@color/colorDialogPop</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">@dimen/text_medium</item>
<item name="android:padding">@dimen/padding_large</item>
<item name="android:layout_marginLeft">@dimen/margin_medium</item>
<item name="android:background">@color/colorAccent</item>
</style>
preference.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/heading_general"
android:layout="@layout/settings_text">
<SwitchPreference
android:padding="@dimen/padding_medium"
android:title="@string/enable_push" />
<SwitchPreference
android:padding="@dimen/padding_medium"
android:title="@string/send_email" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/heading_account"
android:layout="@layout/settings_text">
<EditTextPreference
android:padding="@dimen/padding_medium"
android:title="@string/email" />
<EditTextPreference
android:padding="@dimen/padding_medium"
android:title="@string/name" />
</PreferenceCategory>
</PreferenceScreen>
setting_text.xml for layout of title text
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@android:id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/PreferenceStyle"
>
</TextView>
All I get is this:
Material style PreferenceCategory
does not use android:listSeparatorTextViewStyle
. Instead of trying to mess with the system styles, you can substitute a different layout for all your PreferenceCategory
s and style that however you want.
In res/layout/custom_preference_category.xml
:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/title"
style="@style/CustomPreferenceCategoryText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_medium" />
In res/values/styles.xml
:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="preferenceTheme">@style/PreferenceStyle</item>
</style>
<style name="PreferenceStyle" parent="@style/PreferenceThemeOverlay.v14.Material">
<item name="preferenceCategoryStyle">@style/CustomPreferenceCategory</item>
</style>
<style name="CustomPreferenceCategory" parent="@style/Preference.Category">
<item name="android:layout">@layout/custom_preference_category</item>
</style>
<style name="CustomPreferenceCategoryText" parent="@android:style/Widget.TextView">
<!-- Style your PreferenceCategory here. -->
<item name="android:textColor">@color/colorDialogPop</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">@dimen/text_medium</item>
<item name="android:padding">@dimen/padding_large</item>
<item name="android:background">@color/colorAccent</item>
</style>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With