start an other PreferenceScreen through a PreferenceActivity option

时光总嘲笑我的痴心妄想 提交于 2020-01-23 03:29:13

问题


I'm writing a configuration menu with many options and I'd like to add in the main PreferenceScreen an option that can launch an other PreferenceScreen.

I can't figure out how to create a generic menu entry (so, nor EditTextPreference nor CheckBoxPreference etc.)

Thanks to all.


回答1:


Nest your PreferenceScreen elements. The inner PreferenceScreen will hold the contents of the second screen; the title and description you put on the inner PreferenceScreen will be your "generic menu entry".

For example:

<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android">
    <PreferenceCategory android:title="Simple Preferences">
        <CheckBoxPreference
            android:key="checkbox"
            android:title="Checkbox Preference"
            android:summary="Check it on, check it off"
        />
        <RingtonePreference
            android:key="ringtone"
            android:title="Ringtone Preference"
            android:showDefault="true"
            android:showSilent="true"
            android:summary="Pick a tone, any tone"
        />
    </PreferenceCategory>
    <PreferenceCategory android:title="Detail Screens">
        <PreferenceScreen
            android:key="detail"
            android:title="Detail Screen"
            android:summary="Additional preferences held in another page">
            <CheckBoxPreference
                android:key="checkbox2"
                android:title="Another Checkbox"
                android:summary="On. Off. It really doesn't matter."
            />
        </PreferenceScreen>
    </PreferenceCategory>
    <PreferenceCategory android:title="Other Preferences">
        <EditTextPreference
            android:key="text"
            android:title="Text Entry Dialog"
            android:summary="Click to pop up a field for entry"
            android:dialogTitle="Enter something useful"
        />
        <ListPreference
            android:key="list"
            android:title="Selection Dialog"
            android:summary="Click to pop up a list to choose from"
            android:entries="@array/cities"
            android:entryValues="@array/airport_codes"
            android:dialogTitle="Choose a Pennsylvania city" />
    </PreferenceCategory>
</PreferenceScreen>

(which is from this sample project)



来源:https://stackoverflow.com/questions/5060103/start-an-other-preferencescreen-through-a-preferenceactivity-option

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!