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

Zain
  • 37,492
  • 7
  • 60
  • 84
Tom Taylor
  • 3,344
  • 2
  • 38
  • 63

1 Answers1

1

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.

Zain
  • 37,492
  • 7
  • 60
  • 84
  • Thank you for this answer !! It's much helpful. I'm facing this issue with split screen when during dragging the window size to custom size. Will adding values in dimen.xml help still? – Tom Taylor Feb 07 '21 at 22:08
  • 1
    @TomTaylor logically it will if you pick suitable text sizes compared to screen sizes, I couldn't try it on the emulator as it doesn't support popup-view that shrinks the layout .. let me try it tomorrow on physical device and feedback .. and thanks for your kind words! :) – Zain Feb 07 '21 at 22:14
  • 1
    @TomTaylor just tested it now and worked seamlessly .. although I couldn't see the same issue you have.. but resizing the popup view changes the text size. – Zain Feb 08 '21 at 00:08
  • 1
    Thanks a lot. This works perfectly ! It's due to other layouts and others stacked within `PreferenceScreen` I tried as you said with simple text view and a back button image in my case (to navigate to previous screen) with linear layout - it works perfectly fine. Thanks a lot once again !!! – Tom Taylor Feb 11 '21 at 20:02