首页 > 解决方案 > 为什么我的 Preferences 类中的文本被删掉了?

问题描述

我不明白为什么这里的 wrap_content 在自定义“首选项”中不起作用

看这张图片:

在此处输入图像描述

文本应保持可见。这是我必须在PreferenceScreenxml 文件中进行的一些设置吗?

这是xml布局:

<TextView
    android:id="@+id/textView"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:text="@string/pref_category_remote_battery_title"
    android:textAppearance="?android:attr/textAppearanceListItem"
    android:textColor="@color/default_400"
    app:layout_constraintBottom_toTopOf="@+id/textView2"
    app:layout_constraintEnd_toStartOf="@+id/guideline3"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintWidth_default="wrap" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="8dp"
    android:text="@string/pref_category_remote_battery_switch_summ"
    android:textAppearance="?android:attr/textAppearanceSmall"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toStartOf="@+id/guideline3"
    app:layout_constraintHorizontal_bias="0.02"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView"
    app:layout_constraintWidth_default="wrap" />

<android.support.v7.widget.SwitchCompat
    android:id="@+id/switch_compat"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="24dp"
    android:layout_marginBottom="8dp"
    android:checked="false"
    android:textOff="OFF"
    android:textOn="ON"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="@+id/guideline3"
    app:layout_constraintTop_toTopOf="parent"
    app:showText="true" />

<android.support.constraint.Guideline
    android:id="@+id/guideline3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    app:layout_constraintGuide_percent="0.75" />

这是首选项 xml:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

    <com.sun.power.extended.preferences.ShowRemoteDataPreference android:key="@string/pref_key_category_remote_battery_switch" />


    <com.sun.power.extended.preferences.ShowStatPreference android:key="@string/pref_key_show_stat" />


</PreferenceScreen>

标签: androidlayoutandroid-preferences

解决方案


推荐阅读