7

我有一个首选项页面,我希望在“自定义抽认卡”首选项下有 3 个选项“缩进”或类似子类别。现在它们都在彼此之下,似乎它们适用于不同的设置。我如何使它看起来像“自定义抽认卡”偏好的子类别。这三个选项仅在选中自定义抽认卡时才启用。谢谢!

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<   PreferenceCategory
android:title="Flashcard Selection"
android:key="flashcard_selection">
<CheckBoxPreference
    android:key="all_flashcards"
    android:summary="Display All Flashcards"
    android:title="All Flashcards"
    android:defaultValue="true" 
    />
<CheckBoxPreference
    android:key="custom_flashcards"
    android:summary="Display a customized list of flashcards"
    android:title="Custom Flashcards"
    android:defaultValue="false"/>
    <CheckBoxPreference
        android:key="red_flashcards"
        android:dependency="custom_flashcards"
        android:summary="Display Red Flashcards"
        android:title="Red"
        android:defaultValue="false"
        />
    <CheckBoxPreference
        android:key="yellow_flashcards"
        android:summary="Display Yellow Flashcards"
        android:title="Yellow"
        android:defaultValue="false"
        android:dependency="custom_flashcards"
        />
    <CheckBoxPreference
        android:key="green_flashcards"
        android:summary="Display Green Flashcards"
        android:title="Green"
        android:defaultValue="false"
        android:dependency="custom_flashcards"
        />
    <ListPreference
        android:key="frontside_preference"
        android:summary="Choose what do you want on your front side"
        android:title="Front side"
        android:entries= "@array/Frontside_selection_array"
        android:entryValues ="@array/Frontside_selection_values"
        android:defaultValue="1"
 />



</PreferenceCategory>
 </PreferenceScreen>
4

1 回答 1

1

创建子类别的一个选项是通过将自定义抽认卡 CheckBoxPreference 标记切换为 PreferenceScreen 标记并在三个自定义选项之后将其关闭来使用嵌套首选项屏幕。单击自定义抽认卡选项时,将出现一个带有三个复选框选项的新屏幕。

<PreferenceCategory
    android:key="flashcard_selection"
    android:title="Flashcard Selection">
    <CheckBoxPreference
        android:defaultValue="true"
        android:key="all_flashcards"
        android:summary="Display All Flashcards"
        android:title="All Flashcards" />
    <PreferenceScreen
        android:defaultValue="false"
        android:key="custom_flashcards"
        android:summary="Display a customized list of flashcards"
        android:title="Custom Flashcards" >

        <CheckBoxPreference
            android:defaultValue="false"
            android:dependency="custom_flashcards"
            android:key="red_flashcards"
            android:summary="Display Red Flashcards"
            android:title="Red" />
        <CheckBoxPreference
            android:defaultValue="false"
            android:dependency="custom_flashcards"
            android:key="yellow_flashcards"
            android:summary="Display Yellow Flashcards"
            android:title="Yellow" />
        <CheckBoxPreference
            android:defaultValue="false"
            android:dependency="custom_flashcards"
            android:key="green_flashcards"
            android:summary="Display Green Flashcards"
            android:title="Green" />


    </PreferenceScreen>

</PreferenceCategory>

于 2017-01-29T16:12:20.897 回答