Prefercence 观察来看设计思想应该是简化设置的UI的界面布局所用。

主题是 PreFerenceActivity

1:xml

Code实现:

亦可以自定义PreFerecnce控件 MyPreference

使用:

可以在Activity 主UI 线程中 使用preference xml 的值

1:先在主UI中定义

/*
* If this were my app's main activity, I would load the default values
* so they're set even if the user does not go into the preferences
* screen. Another good place to call this method would be from a
* subclass of Application, so your default values would be loaded
* regardless of entry into your application (for example, a service or
* activity).
*/
PreferenceManager.setDefaultValues(this, R.xml.advanced_preferences, false);

2: 使用

SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
final int counter = sharedPref.getInt(AdvancedPreferences.KEY_MY_PREFERENCE, 0);

更多相关文章

  1. 浅谈Java中Collections.sort对List排序的两种方法
  2. 箭头函数的基础使用
  3. NPM 和webpack 的基础使用
  4. Python list sort方法的具体使用
  5. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  6. python list.sort()根据多个关键字排序的方法实现
  7. Titanium 使用刘明星的Jpush module做android端的消息推送
  8. android.support.v7使用,出错处理
  9. android 中使用TextView实现分段显示不同颜色的字符串

随机推荐

  1. 新装MySql后登录出现root帐号提示mysql E
  2. mysql count详解及函数实例代码
  3. CentOS下重启Mysql的各种方法(推荐)
  4. Mysql5.7.14安装配置方法操作图文教程(密
  5. mysql 详解隔离级别操作过程(cmd)
  6. macOS Sierra安装Apache2.4+PHP7.0+MySQL
  7. MyBatis 如何写配置文件和简单使用
  8. win10免安装版本的MySQL安装配置教程
  9. Mac下安装mysql5.7 完整步骤(图文详解)
  10. ubuntu 15.04下mysql开放远程3306端口