读书人

Preferences(4)组织首选项

发布时间: 2012-09-27 11:11:17 作者: rapoo

Preferences(四)组织首选项
何谓组织首选项啊,实际上就是为首选项分组!分组之后,我们首页只显示组名,当我们点击进去的时候,才会显示具体的首选项列表。如图:Preferences(4)组织首选项代码:view plaincopy to clipboardprint?
<?xml version="1.0" encoding="utf-8"?>?
<PreferenceScreen?
? xmlns:android="http://schemas.android.com/apk/res/android"?
? android:key="edittext_screen"?
? android:title="屏幕标题"?
? android:summary="屏幕简要说明"?
? >?
? <!-- 第一组 -->?
? <PreferenceScreen?
? xmlns:android="http://schemas.android.com/apk/res/android"?
? android:key="edittext_screen"?
? android:title="第一组"?
? android:summary="点击进入第一组首选项"?
? >?
?
? <RingtonePreference?
? android:key="ringtonePreference"?
??? android:summary="简要说明"?
??? android:title="选择系统铃声"?
??? android:ringtoneType="alarm"?
??? android:showSilent="true"?
? >?
? </RingtonePreference>?
? </PreferenceScreen>?
????
? <!-- 第二组 -->?
? <PreferenceScreen?
? xmlns:android="http://schemas.android.com/apk/res/android"?
? android:key="edittext_screen"?
? android:title="第二组"?
? android:summary="点击进入第二组首选项"?
? >?
?? <EditTextPreference?
??? android:dialogTitle="输入您的名称:"?
??? android:key="editTitlePreference"?
??? android:summary="简要说明"?
??? android:title="输入名称"?
? ></EditTextPreference>?
? </PreferenceScreen>?
????
? <!-- 第三组 -->?
? <PreferenceScreen?
? xmlns:android="http://schemas.android.com/apk/res/android"?
? android:key="edittext_screen"?
? android:title="第三组"?
? android:summary="点击进入第三组首选项"?
? >?
?? <EditTextPreference?
??? android:dialogTitle="输入您的名称:"?
??? android:key="editTitlePreference"?
??? android:summary="简要说明"?
??? android:title="输入名称"?
? ></EditTextPreference>?
? </PreferenceScreen>?
????
</PreferenceScreen>???以上的这种方法适合首选项的数目较多时使用。如果我们首选项的数目较少,但是我们依旧想为他们分组下,怎么办呢?我们可以将上面代码中的嵌套PreferenceScreen改为PreferenceCategory,就这么简单!!!
<?xml version="1.0" encoding="utf-8"?>?
<PreferenceScreen?
? xmlns:android="http://schemas.android.com/apk/res/android"?
? android:key="edittext_screen"?
? android:title="屏幕标题"?
? android:summary="屏幕简要说明"?
? >?
? <!-- 第一组 -->?
? <PreferenceCategory?
? xmlns:android="http://schemas.android.com/apk/res/android"?
? android:key="edittext_screen"?
? android:title="第一组"?
? android:summary="点击进入第一组首选项"?
? >?
?
? <RingtonePreference?
? android:key="ringtonePreference"?
??? android:summary="简要说明"?
??? android:title="选择系统铃声"?
??? android:ringtoneType="alarm"?
??? android:showSilent="true"?
? >?
? </RingtonePreference>?
? </PreferenceCategory>?
????
? <!-- 第二组 -->?
? <PreferenceCategory?
? xmlns:android="http://schemas.android.com/apk/res/android"?
? android:key="edittext_screen"?
? android:title="第二组"?
? android:summary="点击进入第二组首选项"?
? >?
?? <EditTextPreference?
??? android:dialogTitle="输入您的名称:"?
??? android:key="editTitlePreference"?
??? android:summary="简要说明"?
??? android:title="输入名称"?
? ></EditTextPreference>?
? </PreferenceCategory>?
????
? <!-- 第三组 -->?
? <PreferenceCategory?
? xmlns:android="http://schemas.android.com/apk/res/android"?
? android:key="edittext_screen"?
? android:title="第三组"?
? android:summary="点击进入第三组首选项"?
? >?
?? <EditTextPreference?
??? android:dialogTitle="输入您的名称:"?
??? android:key="editTitlePreference"?
??? android:summary="简要说明"?
??? android:title="输入名称"?
? ></EditTextPreference>?
? </PreferenceCategory>?
????
</PreferenceScreen>???效果图可就大变样了:??何谓组织首选项啊,实际上就是为首选项分组!分组之后,我们首页只显示组名,当我们点击进去的时候,才会显示具体的首选项列表。如图:?代码:view plaincopy to clipboardprint?
<?xml version="1.0" encoding="utf-8"?>?
<PreferenceScreen?
? xmlns:android="http://schemas.android.com/apk/res/android"?
? android:key="edittext_screen"?
? android:title="屏幕标题"?
? android:summary="屏幕简要说明"?
? >?
? <!-- 第一组 -->?
? <PreferenceScreen?
? xmlns:android="http://schemas.android.com/apk/res/android"?
? android:key="edittext_screen"?
? android:title="第一组"?
? android:summary="点击进入第一组首选项"?
? >?
?
? <RingtonePreference?
? android:key="ringtonePreference"?
??? android:summary="简要说明"?
??? android:title="选择系统铃声"?
??? android:ringtoneType="alarm"?
??? android:showSilent="true"?
? >?
? </RingtonePreference>?
? </PreferenceScreen>?
????
? <!-- 第二组 -->?
? <PreferenceScreen?
? xmlns:android="http://schemas.android.com/apk/res/android"?
? android:key="edittext_screen"?
? android:title="第二组"?
? android:summary="点击进入第二组首选项"?
? >?
?? <EditTextPreference?
??? android:dialogTitle="输入您的名称:"?
??? android:key="editTitlePreference"?
??? android:summary="简要说明"?
??? android:title="输入名称"?
? ></EditTextPreference>?
? </PreferenceScreen>?
????
? <!-- 第三组 -->?
? <PreferenceScreen?
? xmlns:android="http://schemas.android.com/apk/res/android"?
? android:key="edittext_screen"?
? android:title="第三组"?
? android:summary="点击进入第三组首选项"?
? >?
?? <EditTextPreference?
??? android:dialogTitle="输入您的名称:"?
??? android:key="editTitlePreference"?
??? android:summary="简要说明"?
??? android:title="输入名称"?
? ></EditTextPreference>?
? </PreferenceScreen>?
????
</PreferenceScreen>???以上的这种方法适合首选项的数目较多时使用。如果我们首选项的数目较少,但是我们依旧想为他们分组下,怎么办呢?我们可以将上面代码中的嵌套PreferenceScreen改为PreferenceCategory,就这么简单!!!view plaincopy to clipboardprint?
<?xml version="1.0" encoding="utf-8"?>?
<PreferenceScreen?
? xmlns:android="http://schemas.android.com/apk/res/android"?
? android:key="edittext_screen"?
? android:title="屏幕标题"?
? android:summary="屏幕简要说明"?
? >?
? <!-- 第一组 -->?
? <PreferenceCategory?
? xmlns:android="http://schemas.android.com/apk/res/android"?
? android:key="edittext_screen"?
? android:title="第一组"?
? android:summary="点击进入第一组首选项"?
? >?
?
? <RingtonePreference?
? android:key="ringtonePreference"?
??? android:summary="简要说明"?
??? android:title="选择系统铃声"?
??? android:ringtoneType="alarm"?
??? android:showSilent="true"?
? >?
? </RingtonePreference>?
? </PreferenceCategory>?
????
? <!-- 第二组 -->?
? <PreferenceCategory?
? xmlns:android="http://schemas.android.com/apk/res/android"?
? android:key="edittext_screen"?
? android:title="第二组"?
? android:summary="点击进入第二组首选项"?
? >?
?? <EditTextPreference?
??? android:dialogTitle="输入您的名称:"?
??? android:key="editTitlePreference"?
??? android:summary="简要说明"?
??? android:title="输入名称"?
? ></EditTextPreference>?
? </PreferenceCategory>?
????
? <!-- 第三组 -->?
? <PreferenceCategory?
? xmlns:android="http://schemas.android.com/apk/res/android"?
? android:key="edittext_screen"?
? android:title="第三组"?
? android:summary="点击进入第三组首选项"?
? >?
?? <EditTextPreference?
??? android:dialogTitle="输入您的名称:"?
??? android:key="editTitlePreference"?
??? android:summary="简要说明"?
??? android:title="输入名称"?
? ></EditTextPreference>?
? </PreferenceCategory>?
????
</PreferenceScreen>???效果图可就大变样了:?Preferences(4)组织首选项?本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/chenzheng_java/archive/2011/03/29/6286195.aspx

读书人网 >移动开发

热点推荐