标签:
通常app都会有一个设置界面,例如以下:
package com.example.preferenceactivitydemo1; import android.os.Bundle; import android.preference.PreferenceActivity; public class MainActivity extends PreferenceActivity { @SuppressWarnings("deprecation") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.main_preference); } }
<?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:title="标题" > <PreferenceCategory android:summary="分组1" android:title="分组1标题" > <ListPreference android:defaultValue="@string/defaultvalues" android:dialogTitle="对话框标题" android:entries="@array/entries" android:entryValues="@array/entriesvalue" android:key="myListPreference" android:summary="标题说明" android:title="小标题" /> <CheckBoxPreference android:key="doubi" android:summaryOff="逗比模式关闭" android:summaryOn="逗比模式开启" android:title="逗比模式" > </CheckBoxPreference> </PreferenceCategory> <PreferenceCategory android:summary="分组2" android:title="分组2标题" > <SwitchPreference android:key="fly" android:summaryOff="已关闭飞行模式" android:summaryOn="已开启飞行模式" android:switchTextOff="关闭" android:switchTextOn="开启" android:title="飞行模式" > </SwitchPreference> <EditTextPreference android:defaultValue="zhangsan" android:dialogTitle="编辑姓名" android:key="name" android:summary="编辑您的姓名" android:title="编辑" > </EditTextPreference> </PreferenceCategory> </PreferenceScreen>
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">PreferenceActivityDemo1</string> <string name="action_settings">Settings</string> <string name="hello_world">Hello world!</string> <string-array name="entries"> <item>小苹果</item> <item>小香蕉</item> <item>小西瓜</item> </string-array> <string-array name="entriesvalue"> <item>apple</item> <item>banana</item> <item>watermelon</item> </string-array> <string name="defaultvalues">apple</string> </resources>
版权声明:本文博客原创文章,博客,未经同意,不得转载。
【安卓笔记】高速的发展设置界面-----PreferenceActivity
标签:
原文地址:http://www.cnblogs.com/yxwkf/p/4603584.html