将首选项屏幕放置在片段内

问题描述

我想知道是否有可能将PreferenceScreen xml放在ConstraintLayout片段内。我希望我的“偏好设置屏幕”位于“设置”文本下方

enter image description here

这是我的片段xml代码:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/shape_fragment_background"
    tools:context=".ui.fragments.SettingsFragment">

    <TextView
        android:id="@+id/tv_header"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:fontFamily="@font/montserrat"
        android:gravity="center"
        android:text="@string/settings"
        android:textSize="24sp"
        android:textStyle="bold"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

这是我的PreferenceScreen代码:

<androidx.preference.PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <PreferenceCategory app:title="@string/settings">

        <Preference
            app:title="@string/language"
            app:summary="@string/language_summary"
            app:icon="@drawable/ic_baseline_language_24">
            <intent android:action="android.settings.LOCALE_SETTINGS" />
        </Preference>

        <SwitchPreferenceCompat
            app:title="@string/reminder"
            app:summaryOn="@string/reminder_summary_on"
            app:summaryOff="@string/reminder_summary_off"
            app:icon="@drawable/ic_baseline_notifications_24"
            app:key="@string/reminder"/>

    </PreferenceCategory>

    <PreferenceCategory android:title="@string/info">

        <Preference
            app:title="@string/about"
            app:icon="@drawable/ic_baseline_info_24" />

    </PreferenceCategory>

</androidx.preference.PreferenceScreen>

感谢您的帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)