android之喜好設定相關 Preferences(四)組織喜好設定

來源:互聯網
上載者:User

何謂組織喜好設定啊,實際上就是為喜好設定分組!

分組之後,我們首頁只顯示組名,當我們點擊進去的時候,才會顯示具體的喜好設定列表。

代碼:

<?xml version="1.0" encoding="utf-8"?><br /><PreferenceScreen<br /> xmlns:android="http://schemas.android.com/apk/res/android"<br /> android:key="edittext_screen"<br /> android:title="螢幕標題"<br /> android:summary="螢幕簡要說明"<br /> ><br /> <!-- 第一組 --><br /> <PreferenceScreen<br /> xmlns:android="http://schemas.android.com/apk/res/android"<br /> android:key="edittext_screen"<br /> android:title="第一組"<br /> android:summary="點擊進入第一組喜好設定"<br /> ></p><p> <RingtonePreference<br /> android:key="ringtonePreference"<br /> android:summary="簡要說明"<br /> android:title="選擇系統鈴聲"<br /> android:ringtoneType="alarm"<br /> android:showSilent="true"<br /> ><br /> </RingtonePreference><br /> </PreferenceScreen></p><p> <!-- 第二組 --><br /> <PreferenceScreen<br /> xmlns:android="http://schemas.android.com/apk/res/android"<br /> android:key="edittext_screen"<br /> android:title="第二組"<br /> android:summary="點擊進入第二組喜好設定"<br /> ><br /> <EditTextPreference<br /> android:dialogTitle="輸入您的名稱:"<br /> android:key="editTitlePreference"<br /> android:summary="簡要說明"<br /> android:title="輸入名稱"<br /> ></EditTextPreference><br /> </PreferenceScreen></p><p> <!-- 第三組 --><br /> <PreferenceScreen<br /> xmlns:android="http://schemas.android.com/apk/res/android"<br /> android:key="edittext_screen"<br /> android:title="第三組"<br /> android:summary="點擊進入第三組喜好設定"<br /> ><br /> <EditTextPreference<br /> android:dialogTitle="輸入您的名稱:"<br /> android:key="editTitlePreference"<br /> android:summary="簡要說明"<br /> android:title="輸入名稱"<br /> ></EditTextPreference><br /> </PreferenceScreen></p><p></PreferenceScreen><br />

以上的這種方法適合喜好設定的數目較多時使用。

如果我們喜好設定的數目較少,但是我們依舊想為他們分組下,怎麼辦呢?

我們可以將上面代碼中的嵌套PreferenceScreen改為PreferenceCategory,就這麼簡單!!!

<?xml version="1.0" encoding="utf-8"?><br /><PreferenceScreen<br /> xmlns:android="http://schemas.android.com/apk/res/android"<br /> android:key="edittext_screen"<br /> android:title="螢幕標題"<br /> android:summary="螢幕簡要說明"<br /> ><br /> <!-- 第一組 --><br /> <PreferenceCategory<br /> xmlns:android="http://schemas.android.com/apk/res/android"<br /> android:key="edittext_screen"<br /> android:title="第一組"<br /> android:summary="點擊進入第一組喜好設定"<br /> ></p><p> <RingtonePreference<br /> android:key="ringtonePreference"<br /> android:summary="簡要說明"<br /> android:title="選擇系統鈴聲"<br /> android:ringtoneType="alarm"<br /> android:showSilent="true"<br /> ><br /> </RingtonePreference><br /> </PreferenceCategory></p><p> <!-- 第二組 --><br /> <PreferenceCategory<br /> xmlns:android="http://schemas.android.com/apk/res/android"<br /> android:key="edittext_screen"<br /> android:title="第二組"<br /> android:summary="點擊進入第二組喜好設定"<br /> ><br /> <EditTextPreference<br /> android:dialogTitle="輸入您的名稱:"<br /> android:key="editTitlePreference"<br /> android:summary="簡要說明"<br /> android:title="輸入名稱"<br /> ></EditTextPreference><br /> </PreferenceCategory></p><p> <!-- 第三組 --><br /> <PreferenceCategory<br /> xmlns:android="http://schemas.android.com/apk/res/android"<br /> android:key="edittext_screen"<br /> android:title="第三組"<br /> android:summary="點擊進入第三組喜好設定"<br /> ><br /> <EditTextPreference<br /> android:dialogTitle="輸入您的名稱:"<br /> android:key="editTitlePreference"<br /> android:summary="簡要說明"<br /> android:title="輸入名稱"<br /> ></EditTextPreference><br /> </PreferenceCategory></p><p></PreferenceScreen><br />

可就大變樣了:

 

 

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.