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);