android PreferenceScreen使用笔记
2023-09-27 14:27:04 时间
preference.xml
<?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > <Preference android:title="基本信息" android:layout="@layout/text_view"></Preference> <!--自己定义layout--> <CheckBoxPreference android:key="checkbox" android:title="性别" android:summary="男 ,女"/> <RingtonePreference android:key="ringtone" android:title="Ringtone Preference" android:showDefault="true" android:showSilent="true" android:summary="Pick a tone, any tone"/> <ListPreference android:summary="select a list" android:title="Type" android:entries="@array/my_array" <!--string-array--> android:entryValues="@array/my_array" android:key="list"/> <EditTextPreference android:key="edit" android:dialogTitle="nihao" android:title="姓名" /> </PreferenceScreen>
**Activity.java
package com.lin.share; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.Preference.OnPreferenceChangeListener; import android.preference.PreferenceActivity; import android.preference.PreferenceManager; import android.view.View; public class TestPreferenctScreenActivity extends PreferenceActivity { /** Called when the activity is first created. */ ListPreference list; SharedPreferences prefs; EditTextPreference editTextPreference; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preference); prefs=PreferenceManager.getDefaultSharedPreferences(this); list=(ListPreference)findPreference("list"); editTextPreference=(EditTextPreference)findPreference("edit"); editTextPreference.setSummary(prefs.getString("edit","default")); editTextPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { // TODO Auto-generated method stub editTextPreference.setSummary(newValue.toString()); editTextPreference.setDefaultValue(newValue); editTextPreference.setText(newValue.toString()); return false; } }); list.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { System.out.println("change"+newValue); list.setSummary(newValue.toString()); list.setValue(newValue.toString()); return false; } }); } }
相关文章
- Android布局文件的载入过程分析:Activity.setContentView()源代码分析
- Android笔记——Activity中的数据传递案例(用户注冊)
- Android笔记——UI开发
- Android学习笔记——文件路径(/mnt/sdcard/...)、Uri(content://media/external/...)学习
- Android编程权威指南笔记2:解决R文件爆红问题和SDK概念
- 【AGC】【认证服务】认证服务Android sdk 登录返回7400
- Android开发问题笔记
- 《深入解析Android 虚拟机》——第2章 Java虚拟机基础 2.1虚拟机的作用
- Android 接收微信、QQ其他应用打开,第三方分享
- Android学习笔记进阶19 之给图片加边框
- Android学习笔记之Bitmap位图虽触摸点移动
- Android学习笔记之Bitmap位图的缩放
- 在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序
- Android Notification常见样式总结
- Android开发中目前流行控件和知识点总结
- Android 9.0新特性
- Android支付宝SDK开发笔记
- android学习笔记(9)android程序调试学习
- Unity 之 Android发布设置
- 早来的圣诞礼物!--android 逆向菜鸟速參手冊完蛋版
- Android学习笔记:Home Screen Widgets(2):关于Widget
- Android学习笔记(四十):Preference使用
- Android学习笔记(十七)——使用意图调用内置应用程序
- 安卓开发笔记(二十):利用夜神模拟器调试运行Android Studio的apk
- Android控件开发——ListView