0

donc actuellement j'ai un PreferenceFragment avec quelques préférences, comme autant:Modification de texte Couleur de PREFERENCE spécifique dans 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> 

Si je veux changer la couleur de « pref2 » afin qu'il puisse être rouge, comment je le ferais? J'ai regardé quelques solutions différentes. L'un d'entre eux était de créer sa propre mise en page. Alors j'ai essayé:

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

Et cela ne fonctionne pas parce que la marge est éteinte, la hauteur est enveloppée au lieu de parent correspondant, et la taille semble lui aussi. Aucune suggestion?

Répondre

1

Au cas où quelqu'un se demandait, la solution aki j'ai trouvé était de créer un RelativeLayout et hardcode dans la textsize, la marge et la hauteur de la 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>