首页 > 解决方案 > 如何使 PreferenceScreen 的标题可调整大小?

问题描述

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

我为我的应用添加了标题的首选项屏幕。当应用程序在分屏中打开并在窗口中调整为不同大小时,当存在的宽度较小时,标题会消失。

尝试添加,

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

财产,PreferenceScreen但它没有帮助。一些帮助将不胜感激。

标签: androidpreferencescreen

解决方案


就像在这个答案中一样,您可以为该创建自定义布局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_titlevaluesvalues-w600dp


推荐阅读