//程序首先执行此函数
public TypedefDialogPreference(Context context, AttributeSet attrs) {
super(context, attrs);
//通过此句得到布局里的自定义变量dialogMessage里的值,
括号里第2个参数其实是一个resId,要得到其字符串值,在布局里只能用
dialogMessage = "@string/dialogMessage",不能用dialogMessage = "字符串"形式。否则得到的是R.string.empty默认值。
dialogMessage = attrs.getAttributeResourceValue(null, "dialogMessage", R.string.empty);
}
TextView.setText(dialogMessage);//dialogMessage为int型,此函数通过resId得到字符串
TypedArray a = //TypedArray其实就是一个存放资源的Array,context.obtainStyledAttributes(attrs,R.styleable.RadioButton);
this.mValue = a.getString(R.styleable.RadioButton_value);
a. recycle();
<declare-styleable name="RadioButton"><!-- 控件名称-->
<attr name="value" format="string"/><!-- 属性名称,类型-->
</declare-styleable>
Setting里面的一些设置也是通过数据库来保存的,今天才去看个究竟。那通过数据库来保存就会有Provider了,所以就会有SettingsProvider了。数据库的路径就是:/data/data/com.android.providers.settings. 但我们平常获取这里面的数据不是直接通过ContentResolve而是android已经封装了一层,通过Settings这个类来获取,就像MediaStore一样。比如我们获取飞行模式:Settings.System.getInt(mContext.getContentResolver(),Settings.System.AIRPLANE_MODE_ON, 0)