Search code examples
androidandroid-layoutandroid-preferences

How can I change font size in PreferenceScreen


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

I need to change android:title font size of PrefereceCategory, CheckboxPreference and android:summary size. These tags don't have any android:textSize attribute. Can any one help me how to get this?


Solution

  • Finally I was able to solve my problem simply by passing one layout. Maybe this will be helpful to someone. This is my modified preference.xml see below code. We can apply our own properties to pref title and 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>
    

    Please ask me if any queries....Keep Smiling. If this is useful give me one comment.