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 ...
随机推荐
- POJ 3626 BFS
思路:easy BFS //By SiriusRen #include <queue> #include <cstdio> #include <algorithm> ...
- jdbc参数传递
1.jdbc请求设置 将查询结果第一列coupon_id,存放在couponId中; 将查询结果第二列code,存放在coupCode中 2.参数解释: couponId_#:表示查询结果中coupo ...
- Python(三) 变量与运算符
一.什么是变量 变量 = [1,2] 二.变量的命名规则 字母,数字,下划线,首字母不能是数字 系统关键字 不能用在变量名中 保留关键字 区别大小写 a=1, a='1', a=(1,2), ...
- sublime 编辑器汉化
一.下载Sublime编辑器 官网下载地址:http://www.sublimetext.com/3 二.下载汉化包 汉化包下载地址:http://files.cnblogs.com/akwwl/su ...
- CodeBlocks 配色方案
搜索<colour_sets>,在</ACTIVE_LANG>下加入: 有几种经典方案,包括vim,desert,sublime,ulipad,oblivion,darkgra ...
- angular-cli6使用ng serve --o 控制台报错Invalid Host Header
angular-cli6使用ng serve --o 运行创建的项目,能正常访问,但是控制台一直在报错,点击报错能看到是因为webpack的webpack-dev-server里报的错, 看到网上介绍 ...
- 今日SGU 5.15
最近事情好多,数据库作业,没天要学2个小时java,所以更新的sgu就比较少了 SGU 131 题意:给你两种小块一种,1*1,一种2*2-1*1,问你填满一个m*n的矩形有多少钟方法,n和m小于等于 ...
- 数据库更新DATE类型的时间
使用to_date() 进行格式转换 to_date('2018/11/16','yyyy/MM/dd') update tableName t set t.shipment_date = to_da ...
- Android基于XMPP Smack及Openfire学习笔记(1)
之前开发的项目中实用到IM聊天功能.可是这块功能公司有专门的IM团队来开发,由他们开发好后.直接接入到我们APP中.我參与写IM相关功能非常地少,所以也一直想学习相关知识 . 眼下Android主要用 ...
- php将数组或字符串写入文件
//将数组保存在文件里 function export_to_file($file, $variable) { $fopen = fopen($file, 'wb'); if (!$fopen) { ...