Android PreferenceScreen介绍
源代码:
http://download.csdn.net/detail/zhuimengandyue/5914779
如上图所示效果,实现起来很简单。只需要借助PreferenceScreen类即可。在项目资源文件中新建xml文件夹,在里面新建preferences.xml文件.
根元素为PreferenceScreen 代表显示一整个屏幕,内部嵌套PreferenceCategory标签,表示偏好类别,在PreferenceCategory标签内部可以随便存放复 选框,输入框,列表等显示控件.可包含的控件内容在android.preference包下可查阅.xml文件编写好后,需要加载到activity 中,对于偏好显示的xml加载,可以使用PreferenceActivity中的addPreferencesFromResource(),所以 Activity需要继承PreferenceActivity.
复写activity中的onPreferenceTreeClick 方法,在对屏幕显示的内容进行操作时,会触发此方法,在方法内部通过调用。
preference.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
>
<PreferenceCategory android:title="Jamendo" >
<CheckBoxPreference
android:key="checkbox"
android:summary="Listen only in wifi network area"
android:title="Wifi only mode" />
<EditTextPreference
android:dependency="checkbox"
android:key="edittextpreffer"
android:summary="Personallize your jamendo client"
android:title="User name" />
<ListPreference
android:dependency="checkbox3"
android:entries="@array/stream_codecs"
android:entryValues="@array/stream_codecs_values"
android:key="listpreffer"
android:summary="select your preferred codec"
android:title="Download format" />
<CheckBoxPreference
android:disableDependentsState="true"
android:key="checkbox3"
android:summaryOn="Disable listening abroad"
android:title="Disable listening abroad" />
</PreferenceCategory>
<PreferenceCategory
android:summary="lalalalalalalla"
android:title="3rd Party Applications" >
<CheckBoxPreference
android:key="checkbox2"
android:summaryOff="fdsfsddddddddddddddddddddddddddddddd"
android:title="fdsfsafsdfdsfds" />
<CheckBoxPreference
android:key="checkbo"
android:summaryOff="fdsfsddddddddddddddddddddddddddddddd"
android:title="fdsfsafsdfdsfds" />
<RingtonePreference
android:key="rengtone"
android:summary="select rengtone"
android:title="rengtones" />
<Preference
android:title="tiantianxiangshang"/>
</PreferenceCategory>
</PreferenceScreen>
setting.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:minHeight="50dip"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="50dip"
android:orientation="horizontal"
android:paddingLeft="13dip"
android:background="#4b0082"
android:paddingRight="13dip" >
<ImageView
android:layout_width="48dip"
android:layout_height="48dip"
android:src="@drawable/ic_launcher" >
</ImageView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="13dip" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="setting"
android:textColor="#ffffff"
android:textSize="18dip" >
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="12dip" >
</TextView>
<TextView
android:id="@+id/ItemsCountTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:textColor="#ffffff"
android:textSize="12dip" >
</TextView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:scrollingCache="false">
</ListView>
</LinearLayout>
java代码:
package com.example.test;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.view.Window;
public class SettingActivity extends PreferenceActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference);
setContentView(R.layout.setting);
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
Preference preference) {
// TODO Auto-generated method stub
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
}
重要的几个属性:1、android:dependency="config_anonymous"这个属性指定该设置项依赖于前面key="config_anonymous" 的CheckBoxPreference的值,
如果config_anonymous的值为真(即选中状态),则下面的设置项可用,即enabled的,否则为disabled。
但是,如果逻辑刚好相反,即config_anonymous的值为真的时候,需要禁用下面的设置项。要实现这个就需要在CheckBoxPreference上设置了,
即添加android:disableDependentsState="true"这个属性,这个属性的意思是,当CheckBoxPreference的值为真的时候
2、使用PreferenceActivity时,碰到配置文件的ListPreference有两个属性android:entries,android:entryValues。这两个属性其实就和html的option的显示内容和真实值一样。
android:entries设置的内容是我们在设置时看到的内容,而android:entryValues就是保存在preferences.xml中的值。
Android PreferenceScreen介绍相关推荐
- 【转】Android bluetooth介绍(三): 蓝牙扫描(scan)设备分析
原文网址:http://blog.csdn.net/xubin341719/article/details/38584469 关键词:蓝牙blueZ A2DP.SINK.sink_connect.s ...
- android AsyncTask介绍(转)
android AsyncTask介绍 AsyncTask和Handler对比 1 ) AsyncTask实现的原理,和适用的优缺点 AsyncTask,是android提供的轻量级的异步类,可以直接 ...
- Android类库介绍
Android类库介绍 GPhone开发包Android SDK含了很多丰富的类库: android.util 涉及系统底层的辅助类库 android.os 提供了系统服务.消息传输.IPC管道 an ...
- 1.android体系结构介绍
一.Android的介绍 android介绍见百度百科:Android的介绍,度娘把Android介绍的这么清楚,如果谷歌是Android的爹,那度娘就是娘了. 二.Android的架构图 andro ...
- 作业Android自我介绍
***Android自我介绍***
- Android HIDL 介绍学习之客户端调用
应上一篇文章Android HIDL 介绍学习_Super Jang的博客-CSDN博客_安卓hidl读者的要求,本文更新客户端调用方法. hidl的客户端调用相比服务端的实现要简单很多,本次我们通过 ...
- Android开发介绍
Android开发介绍 这个教程设计是帮助你学习基础的Android开发和快速搭建您的开发环境.这个是在我的Window 7上编写的,当然它也支持Linux(uBuntu).Mac OS其他支持And ...
- android 模拟器的使用(Android模拟器介绍及创建)
做了这么久的android开发,一直想把在开发过程中积累的经验或问题总结一下,可是都没有时间,现在有一点点空闲,所以慢慢把我在android中遇到的问题整理一下写出来,供自己以后参考,也希望和大家一起 ...
- Android bluetooth介绍(一):基本概念及硬件接口
关键词:蓝牙硬件接口 UART PCM blueZ 版本:基于android4.2之前版本 bluez 内核:linux/linux3.08 系统:android/android4.1.3.4 ...
- Android bluetooth介绍(二): android 蓝牙代码架构及其uart 到rfcomm流程
关键词:蓝牙blueZ UART HCI_UART H4 HCI L2CAP RFCOMM 版本:基于android4.2之前版本 bluez内核:linux/linux3.08 系统:an ...
最新文章
- Android基础--tools:context=.TestActivity作用
- python3.4安装suds
- windows下安装配置cwrsync
- Fckeditor配置 for ASP.NET
- cocos2d 环绕已知点移动一圈
- java .listfiles_Java File.listFiles()
- # 20172307 2018-2019-1 《程序设计与数据结构》第5周学习总结
- linux set权限,Linux 特殊权限set_uid(示例代码)
- 树形结构 —— 树与二叉树
- v-bind:href= 拼接字符串 - 代码篇
- Delphi中exit、break、continue等跳出操作的区别
- 盖瑞特金属探测门受多个严重漏洞影响,可遭篡改
- [转载] 夯实Java基础系列8:深入理解Java内部类及其实现原理
- random_state的值如何选_算法萌新如何学好动态规划(3)
- 实例构造函数与静态构造函数执行顺序
- 通俗理解什么是隐马尔科夫模型(hmm)
- python没有pygame_教程丨python 做一个简单的MP3
- 机械制图之平面与圆柱体表面的交线
- Huffman编码之文件的解/压缩
- 关于使用腾讯云播放器的遇到的坑
热门文章
- android studio 软件使用 详细说明
- python怎么生成图_python 生成图表
- redis客户端工具redis-insight推荐
- mysql多表操作常用语法命令
- 阿里云mysql数据库日志_阿里云mysql数据库操作日志
- 国二计算机考试office快捷键,全国计算机二级考试(Office)应试技巧
- 联想y50更换固态硬盘_联想y50怎么加固态硬盘而不换原来的机器硬盘?
- SI 9000 及阻抗匹配学习笔记(三)
- 读《About Face 4 交互设计精髓》2
- Axure 8.1.0.3382 激活码(转)