0
具體PreferenceScreen的更改文本顏色

所以目前我有一個PreferenceFragment與一對夫婦的喜好在裏面,像這樣:在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> 

而且它不工作,因爲利潤率是關閉的,高度包裹,而不是匹配的父,而且規模似乎斷爲好。有什麼建議麼?

回答

1

爲了防止有人想知道時,哈克溶液我發現是創建一個RelativeLayout的和在TEXTSIZE,餘量硬編碼,和的TextView的

<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> 
高度
相關問題