setting-在设置中添加新的选项
如下图的“通知栏调出方式”

具体实现如下
1.在
res/xml/settings_headers.xml
文件中添加如下内容
<preference-headers
xmlns:android="http://schemas.android.com/apk/res/android">
<header
android:id="@+id/quick_pulldown"
android:fragment="com.android.settings.QuickPullDown"
android:title="@string/quick_pulldown"
android:icon="@drawable/ic_quick_pulldown" />
</preference-headers>
2.关联的fragment类如下
public class QuickPullDown extends SettingsPreferenceFragment implements
OnPreferenceClickListener { private Context mContext; private AudioProfilePreference mOffPressPref;
private AudioProfilePreference mRightPressPref;
private AudioProfilePreference mLeftPressPref;
private static final int QS_QUICK_PULLDOWN_DEFAULT_VALUE = 0;
private static final String OFF = "off";
private static final String RIGHT = "right";
private static final String LEFT = "left"; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = getActivity();
addPreferencesFromResource(R.xml.quick_pulldown); mOffPressPref = (AudioProfilePreference) findPreference(OFF);
mRightPressPref = (AudioProfilePreference) findPreference(RIGHT);
mLeftPressPref = (AudioProfilePreference) findPreference(LEFT);
mOffPressPref.isShowDetailsView = false;
mRightPressPref.isShowDetailsView = false;
mLeftPressPref.isShowDetailsView = false;
mOffPressPref.setOnPreferenceClickListener(this);
mRightPressPref.setOnPreferenceClickListener(this);
mLeftPressPref.setOnPreferenceClickListener(this);
refreshPressState();
} @Override
public void onResume() {
super.onResume();
getListView().setDivider(null);
getListView().setBackgroundResource(R.drawable.funui_background);
getListView().setSelector(android.R.color.transparent);
new BackgroundChooser().justDoIt(getPreferenceScreen());
} @Override
public boolean onPreferenceClick(Preference preference) {
if (preference instanceof AudioProfilePreference) {
if (preference == mOffPressPref) {
Settings.System.putInt(mContext.getContentResolver(), QS_QUICK_PULLDOWN, 0);
} else if (preference == mRightPressPref) {
Settings.System.putInt(mContext.getContentResolver(), QS_QUICK_PULLDOWN, 1);
} else if (preference == mLeftPressPref) {
Settings.System.putInt(mContext.getContentResolver(), QS_QUICK_PULLDOWN, 2);
}
refreshPressState();
}
return true;
} public void refreshPressState() {
int value = Settings.System.getInt(
getContentResolver(), QS_QUICK_PULLDOWN, QS_QUICK_PULLDOWN_DEFAULT_VALUE); mOffPressPref.setRadioButtonClickable(false);
mRightPressPref.setRadioButtonClickable(false);
mLeftPressPref.setRadioButtonClickable(false);
switch (value) {
case 0:
mOffPressPref.setChecked();
break;
case 1:
mRightPressPref.setChecked();
break;
case 2:
mLeftPressPref.setChecked();
break;
default:
break;
}
}
}
3.这个类中用到的布局文件如下
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <com.android.settings.FunuiPreferenceCategory
android:key="quick_pulldown_setting"
android:persistent="false"
android:title="@string/quick_pulldown"> <com.mediatek.audioprofile.AudioProfilePreference
android:key="off"
android:layout="@layout/funui_switch_preference_full"
android:title="@string/quick_pulldown_off"
android:summary="@string/quick_pulldown_off_describe"/> <com.mediatek.audioprofile.AudioProfilePreference
android:key="right"
android:layout="@layout/funui_switch_preference_full"
android:title="@string/quick_pulldown_right"
android:summary="@string/quick_pulldown_right_describe"/> <com.mediatek.audioprofile.AudioProfilePreference
android:key="left"
android:layout="@layout/funui_switch_preference_full"
android:title="@string/quick_pulldown_left"
android:summary="@string/quick_pulldown_left_describe"/>
</com.android.settings.FunuiPreferenceCategory> </PreferenceScreen>
这些其实就是setting这个模块的基本实现框架了
如何设定它的显示跟隐藏呢,主要是在这个
src/com/android/settings/Settings.java
类中实现的,代码如下
public void updateHeaderList(List<Header> target) {
if (id == R.id.quick_pulldown) {
target.remove(header);
}
}
setting-在设置中添加新的选项的更多相关文章
- VMware 虚拟机中添加新硬盘的方法(转载)
随着在虚拟机中存储的东西的逐渐的增加,虚拟机的硬盘也逐渐告急,因此急需拓展一块新的虚拟磁盘.以下便是在VMware 中添加新的虚拟磁盘的方法: 一.VMware新增磁盘的设置步骤 (建议:在设置虚 ...
- 详解VMware 虚拟机中添加新硬盘的方法
一.VMware新增磁盘的设置步骤 (建议:在设置虚拟的时候,不要运行虚拟机的系统,不然添加了新的虚拟磁盘则要重启虚拟机) 1.选择“VM”----“设置”并打开,将光标定位在“硬盘(SCSI)”这一 ...
- discuz 修改亮剑积分商城2.91模板(在常用设置中添加商场首页排序方式的背景颜色)
在应用 -> 积分商城 -> 常用设置 中添加 商场首页排序方式 的背景颜色修改功能 步骤: 1.找到并打开此页面对应的模板source\plugin\aljsc\template\set ...
- 在ubuntu中添加新硬盘
在ubuntu中添加新硬盘 转载于 http://www.cnblogs.com/unipower/archive/2009/03/08/1406230.html 前言 安装新硬盘这种事情并不会经常 ...
- 向CDH5集群中添加新的主机节点
向CDH5集群中添加新的主机节点 步骤一:首先得在新的主机环境中安装JDK,关闭防火墙.修改selinux.NTP时钟与主机同步.修改hosts.与主机配置ssh免密码登录.保证安装好了perl和py ...
- (原)torch7中添加新的层
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6069627.html 参考网址: http://torch.ch/docs/developer-doc ...
- gitignore文件中添加新过滤文件,但是此文件已经提交,如何解决?
gitignore文件中添加新过滤文件,但是此文件已经提交到远程库,如何解决? 第一步,为避免冲突需要先同步下远程仓库 git pull 第二步,在本地项目目录下删除缓存 git rm -r --ca ...
- C# 往Datatable中添加新行的步骤
以一个实例说明 //录入年份绑定 public void YearList(FineUIPro.DropDownList ddlYear) { //年份从15年到当前年//起止年份 ; int yea ...
- SqlServer表中添加新字段
表中添加新字段ALTER TABLE 表名 ADD 字段名 VARCHAR(20) NULL 表中添加自增idalter table lianxi add id int primary key IDE ...
随机推荐
- 快速select算法的实现
代码来自: http://blog.csdn.net/v_JULY_v 算法思想: // Quick_select.cpp : 定义控制台应用程序的入口点. // #include "std ...
- 异常:error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'
error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name 'System. ...
- css3透明度
http://www.haorooms.com/post/css_common //透明度 div{ background: #00c2de; opacity: 0.9; filter: alpha( ...
- Codefroces A. Saitama Destroys Hotel
A. Saitama Destroys Hotel time limit per test 1 second memory limit per test 256 megabytes input sta ...
- window.location.href和window.top.location.href的区别
if (window.location.href == window.top.location.href) { window.top.location.href = "/index. ...
- 开发板ping得通本地,但是不能上网
在3531D的开发板上面接入LAN7500的USB转以太网口,加载完驱动后. 然后开启eth1 查看一下ifconfig,发现没有ip,配置一下ip 直接ping本地发现可以ping得通,代表链路是连 ...
- CSDN博客给我带来的一些诱惑和选择机会(二):HR“邀请于我”,猎头“有求于我”
上次,2013年10月8日 ,分享了一篇颇具"正能量"的文章CSDN博客给我带来的一些诱惑和选择机会,获得了很好的正面效果. 10月份,又发生了很多有趣.有意义的事情. 其中,有一 ...
- XCode6报数组越界错误的问题
今天碰到一个非常奇葩的问题, 调试了半天: 错误:"index 0 beyond bounds for empty array", 意思就是说数据源数组为nil, 所以你调用直接 ...
- android 动态设置TextView值,例:金额添加
一说到动态递增设置TextView值,非常多人应该立即就想到起个线程,让后在线程中睡眠指定时间,使用handler发送消息更新TextView值! 这样是实现了动态递增设置TextView值可是效率不 ...
- 47.Express文件上传
转自:http://www.runoob.com/nodejs/nodejs-express-framework.html 文件上传 以下我们创建一个用于上传文件的表单,使用 POST 方法,表单 e ...