更改首选项屏幕的首选项标题文本颜色并向左对齐

时间:2018-01-03 06:14:21

标签: android preference preferencefragment android-text-color

出于某种原因,注销Button正在被推向正确。怎么解决这个?我在自定义布局TextViewLinearLayout中执行的任何操作都不起作用。我只想更改此首选项的颜色

<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>

我在这里使用布局

   <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>

您可以在下面看到截图。

preference layout

1 个答案:

答案 0 :(得分:1)

终于明白了。 当我尝试使用layout属性时,它没有显示任何内容,因为我在自定义布局的textview中设置了android:id="@android:id/title"

删除android:id="@android:id/title"并将首选项自定义布局设置为android:布局 =“@ layout / pref_account_text”而不是 widgetLayout 解决了它