如何在“首选项”中执行“子类别”

时间:2013-08-15 20:51:19

标签: java android preferences

我有一个Preference页面,我希望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>

1 个答案:

答案 0 :(得分: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>