androidpreferencescreen

How to make title of PreferenceScreen resizable?


<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
                  android:title="@string/game_title">

I've a preference screen for my app for which I've added the title. When the app gets opened in split screen and resized to different size in window, the title is disappearing when the width present is smaller.

Tried adding,

android:layout_height="wrap_content"
android:layout_width="wrap_content"

property to the PreferenceScreen but it didn't help. Some help would be appreciated.


Solution

  • Like in this answer, you can create a custom layout for the PreferenceScreen and apply it with android:layout attribute

    <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
                      android:layout="@layout/preference_title"
                      android:title="@string/game_title">
    

    preference_title.xml layout

    <?xml version="1.0" encoding="utf-8"?>
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@android:id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="@dimen/preference_title"/>
    

    And create different versions of res/values/dimen.xml file to have variable value of the title text size (@dimen/preference_title) that are proportional to possible screen widths .. typically you'll have different versions values directory, for instance for a screen width of w600dp, you'll have values-w600dp directory.