【问题标题】:Changing Text Color of Specific PreferenceScreen in PreferenceFragment更改 PreferenceFragment 中特定 PreferenceScreen 的文本颜色
【发布时间】:2017-12-31 20:52:48
【问题描述】:

所以目前我有一个 PreferenceFragment 有几个偏好,如下所示:

<PreferenceScreen xmlns:tools="http://schemas.android.com/tools"
              xmlns:android="http://schemas.android.com/apk/res/android">
    <PreferenceCategory
        android:title="menu"
        android:key="menu">

        <PreferenceScreen
            android:title="pref1"
            android:key="pref1" />

        <PreferenceScreen
            android:title="pref2"
            android:key="pref2" />
    </PreferenceCategory>
</PreferenceScreen>

如果我想将“pref2”的颜色更改为红色,我该怎么做?我看过几个不同的解决方案。其中之一是创建自己的布局。所以我尝试了:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

    <TextView
        android:textColor="#FF0000"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="pref2"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true"/>
</RelativeLayout>

它不起作用,因为边距关闭,高度被包裹而不是匹配父项,并且尺寸似乎也关闭了。有什么建议吗?

【问题讨论】:

    标签: android layout textview preferenceactivity preferencefragment


    【解决方案1】:

    如果有人想知道,我发现的 hacky 解决方案是在 TextView 的文本大小、边距和高度中创建一个 RelativeLayout 和硬编码

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:id="pref2"
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:orientation="horizontal">
    
        <TextView
            android:textColor="#FF0000"
            android:textSize="16sp"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/menu_sign_out_text"
            android:layout_marginStart="16dp"
            android:gravity="center"/>
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-22
      • 1970-01-01
      • 2016-02-02
      • 2012-03-13
      • 1970-01-01
      • 1970-01-01
      • 2018-04-29
      • 2013-04-17
      相关资源
      最近更新 更多