Search code examples
androidpreferencepreferencefragmentandroid-text-color

Change preference screen's preference item title text color and align left


For some reason the sign-out Button is being pushed right. How to resolve this? Anything I do in the custom layout's TextView and LinearLayout does not work. I just want to change this preference item's color

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <TextView
        android:id="@android:id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/coral"
        android:textSize="16sp"
        android:text="@string/title_sign_out"/>
</LinearLayout>

And i use the layout here

   <PreferenceCategory android:title="@string/title_section">

        <Preference android:key="@string/key_account" />

        <Preference
            android:key="@string/key_logout_btn"
            android:widgetLayout="@layout/pref_account_text" />

    </PreferenceCategory>

You can see the screenshot below.

preference layout


Solution

  • figured it out finally. When i tried with layout attribute, it wasn't showing anything because i had android:id="@android:id/title" set in the custom layout's textview.

    So removing android:id="@android:id/title" and setting the preference custom layout to android:layout="@layout/pref_account_text" instead of widgetLayout resolved it