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 ...
随机推荐
- 消息推送学习一、原生Socket的使用
消息推送也是客户端和服务器连接然后进行交互的一种形式,但是不同于HTTP的连接,这种连接需要长时间的进行,当有消息时可以及时推送到客户端.除此之外还有多个用户,可能需要针对其身份进行不同的推送等等要求 ...
- ubuntu server 网络配置,主机名配置
一.通过命令ifconfig -a 查看可用网络设备 通过上面的命令,本机可用的网络设备为enp4s0f0 和enp4s0f1 ,不同的系统版本和硬件配置网络设备名可能不一样,所以一定要先确认本机可用 ...
- Tensorlfow学习笔记----collection
本文来源:http://blog.csdn.net/u012436149/article/details/53894354 tensorflow 之 collection tensorflow的c ...
- 学习TF:《TensorFlow实战》中文版PDF+源代码
深度学习乃至人工智能正逐渐在FinTech领域发挥巨大的作用,其应用包括自动报告生成.金融智能搜索.量化交易和智能投顾.而TensorFlow为金融业方便地使用深度学习提供了可能.<Tensor ...
- JS jQuery查看系统中安装的字体
1.下载插件:FontDetect插件 地址:http://www.lalit.org/lab/javascript-css-font-detect/ 或者复制以下代码到fontdetect.js: ...
- 【Henu ACM Round#15 C】 A and B and Team Training
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举第一种方法. 剩下的全都个第二种方法. 看看能组成多少个队伍就可以了. [代码] #include <bits/stdc+ ...
- int long long 的取值范围
unsigned int 0-4294967295 //整型的每一种都有无符号(unsigned)和有符号(signed)两种类型(float和double总是带符号的),在默认情况下声明 ...
- jquery10 闭包示例
o = { a:1, o:{ b:2, f : function(){ alert(o.a); alert(o.b);//undefined } } } o.o.f(); o = { a:7, o : ...
- vim 基础学习之普通模式
.操作 = 操作符 + 动作 aaa bbb例如,d是删除命令,b是移动到距离光标最近的字符串开头当我们执行db的时候,就会删除光标(不包括光标位置)到最近字串开头之间的字符dj则会删除光标所在行以及 ...
- POJ 2391 Floyd+二分+拆点最大流
题意: 思路: 先Floyd一遍两两点之间的最短路 二分答案 建图 跑Dinic 只要不像我一样作死#define int long long 估计都没啥事-- 我T到死辣--.. 最后才改过来-- ...