如何使 PreferenceScreen 的标题可调整大小?

How to make title of PreferenceScreen resizable?

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

我的应用程序有一个首选项屏幕,我已为其添加了标题。 window 当应用程序在分屏中打开并调整为不同大小时,当宽度变小时标题会消失。

尝试添加,

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

属性 到 PreferenceScreen 但它没有帮助。一些帮助将不胜感激。

this answer 一样,您可以为 PreferenceScreen 创建自定义布局并使用 android:layout 属性应用它

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

preference_title.xml布局

<?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"/>

并创建不同版本的 res/values/dimen.xml 文件,使标题文本大小 (@dimen/preference_title) 的可变值与可能的屏幕宽度成比例..通常你会有不同的版本 values 目录,例如对于 w600dp 的屏幕宽度,您将拥有 values-w600dp 目录。