2011-03-17 7 views
17
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> 
    <PreferenceCategory 
     android:title="First Category" 
     android:textSize="20px"> 

     <CheckBoxPreference 
      android:title="Checkbox Preference" 
      android:defaultValue="false" 
      android:summary="This preference can be true or false" 
      android:key="checkboxPref" /> 

    </PreferenceCategory> 
</PreferenceScreen> 

Necesito cambiar android:title tamaño de fuente de PrefereceCategory, CheckboxPreference y android:summary tamaño. Estas etiquetas no tienen ningún atributo android:textSize. ¿Alguien puede ayudarme a obtener esto?¿Cómo puedo cambiar el tamaño de fuente en la pantalla PREFERENCE

Respuesta

49

Finalmente pude resolver mi problema simplemente pasando un diseño. Tal vez esto sea útil para alguien. Este es mi preference.xml modificado ver código a continuación. Podemos aplicar nuestras propias propiedades para pref title y summary.

preference.xml:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> 
    <PreferenceCategory 
     android:title="First Category" 
     android:textSize="20px" 
     android:layout="@layout/mylayout">    

     <CheckBoxPreference 
      android:title="Checkbox Preference" 
      android:defaultValue="false" 
      android:summary="This preference can be true or false" 
      android:key="checkboxPref" 
      android:layout="@layout/mylayout"/> 

    </PreferenceCategory> 
</PreferenceScreen> 

mylayout.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <TextView android:id="@android:id/title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="40sp"/> 

    <TextView android:id="@android:id/summary" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="26sp"/> 

</LinearLayout> 

favor pregúnteme si cualquier pregunta .... Guarde el sonreír. Si esto es útil dame un comentario.

+1

Me fue útil. Pero, ¿cómo puedo obtener las fuentes del sistema, los márgenes y los colores para los elementos de la lista de preferencias y agregarlos a mylayout.xml? – degratnik

+5

Muchas gracias por los consejos. Tengo un comentario para mejorar tu respuesta anterior. Debe especificar textSizes como "sp", o "dp", definitivamente no como "px". El uso de "dp" hará que la fuente tenga el mismo tamaño físico en todos los dispositivos, "sp" es más o menos como "dp", pero el tamaño seguirá la configuración del dispositivo para tamaños de fuente globales (p.tamaño grande/mediano/pequeño en Configuración-Pantalla en Android 4). Mi opinión es que "sp" es el más apropiado aquí. –

+0

¿Cómo puedo cambiar los blue drawable predeterminados para la preferencia de casilla de verificación. – Dory

4

Modifiqué la respuesta de Kumar a esto para ICS y superior. Coloqué este diseño en values-v11 para apuntar a los dispositivos API nivel 11+.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <TextView android:id="@+android:id/title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="18dp" 
     android:textColor="?android:attr/textColorPrimary" 
     android:paddingLeft="8dip"/> 

    <TextView android:id="@+android:id/summary" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="14dp" 
     android:textColor="?android:attr/textColorSecondary" 
     android:paddingLeft="8dip"/> 

</LinearLayout> 
10

Para mí, el diseño publicado por praneetloke hizo desaparecer el widget de las preferencias que tienen un widget de asociado, por ejemplo, una casilla de verificación. Hay un LinearLayout con id/widget_frame que se necesita para el widget. Lo siguiente funcionó para mí, en Android 2.3 a 4.2.2. El único cambio que tuve que hacer fue establecer android: visibility = "gone" en el diseño que contiene el icono de preferencia, que no estaba disponible en Gingerbread.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_vertical" 
    android:minHeight="?android:attr/listPreferredItemHeight" 
    android:paddingLeft="8dip" 
    android:paddingRight="?android:attr/scrollbarSize" > 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:gravity="center" 
     android:minWidth="0dp" 
     android:orientation="horizontal" 
     android:visibility="gone" > 

     <ImageView 
      android:id="@+android:id/icon" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:minWidth="48dp" 
      android:paddingRight="8dip" /> 
    </LinearLayout> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:paddingBottom="6dip" 
     android:paddingRight="8dip" 
     android:paddingTop="6dip" > 

     <TextView 
      android:id="@+android:id/title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:ellipsize="marquee" 
      android:fadingEdge="horizontal" 
      android:singleLine="true" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <TextView 
      android:id="@+android:id/summary" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@android:id/title" 
      android:layout_below="@android:id/title" 
      android:maxLines="4" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="?android:attr/textColorSecondary" /> 
    </RelativeLayout> 

    <!-- Preference should place its actual preference widget here. --> 

    <LinearLayout 
     android:id="@+android:id/widget_frame" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:gravity="center" 
     android:minWidth="48dp" 
     android:orientation="vertical" /> 

</LinearLayout> 

Referencias: Las dimensiones predeterminadas utilizadas en el diseño están aquí GrepCode /res/values/dimens.xml. El diseño del elemento de preferencia real está aquí GrepCode /res/layout/preference_holo.xml. Tenga en cuenta que también hay una versión no holo llamada preference.xml.

+0

Esta es la mejor respuesta. ¡Asombroso! –

0

Eche un vistazo a mi respuesta a esto: Android PreferenceScreen title in two lines.

También puede cambiar la fuente si lo desea. Sólo tiene que añadir esto:

Typeface myTypeface = Typeface.createFromAsset(textView.getContext().getAssets(),"fonts/your_font_name.ttf"); 
    if (textView != null) { 
     textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textView.getContext().getResources().getDimension(R.dimen.text_size_from_dimen)); 
     textView.setTypeface(myTypeface); 
    } 
1

En realidad se puede echar un vistazo a la disposición que se utiliza en la plataforma específica en la carpeta de diseño se encuentra en:

<android-sdk>\platforms\android-<level>\data\res\layout 

Preferencias diseños comienzan con preference_ prefijo.

0

Solo una pequeña revisión en el código de diseño. "@ + Android: id/summary" está causando el símbolo No se puede resolver por mí. entonces quito el signo '+' y el código funciona

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

    <TextView android:id="@android:id/title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="40px"/> 

    <TextView android:id="@+android:id/summary" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="26px"/> 

</LinearLayout> 
Cuestiones relacionadas