两个主要的类 : TypedValue & Resources
TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard);
R.styleable.Keyboard_Key_android_codes, codesValue);
a.getText(
R.styleable.Keyboard_Key_android_popupCharacters);
a.getResourceId(
R.styleable.Keyboard_Key_android_popupKeyboard, 0);
a.getBoolean(
R.styleable.Keyboard_Key_android_isRepeatable, false);
a.getDrawable(R.styleable.Keyboard_Key_android_keyIcon);
if (icon != null) {
icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
}
res.getDrawable(R.drawable.e00e)
有关key在xml定义的所有属性,都在Keyboard.java中的key 抽象类中有对应声明;
在API,Values/attrs.xml中;有所有的resources 对应的名称,以及各自属性的声明;通过一次编译后,系统将自动把对应的属性在R.java中生成序列号;
利用TyprArray可以获取每个key各自对应的不同属性;
(: 每页只有当前页的按钮背景不同,当获取key background时,变更改了原先统一的key background; 而当要给每个Key设定新的属性Icon时, 同样在attrs.xml中先声明,再逐个获取 );
TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard);
/*parser 可以通过 getApplicationContext().getResources().getXml(R.xml.file); 来获得的对应的xml文档解析器
AttributeSet attrs = Xml.asAttributeSet(xml);*/
Resources askResources= askContext.getApplicationContext().getResources();
R.styleable.Keyboard_Key_android_codes, codesValue);
a.getText(
R.styleable.Keyboard_Key_android_popupCharacters);
a.getResourceId(
R.styleable.Keyboard_Key_android_popupKeyboard, 0);
a.getBoolean(
R.styleable.Keyboard_Key_android_isRepeatable, false);
a.getDrawable(R.styleable.Keyboard_Key_android_keyIcon);
if (icon != null) {
icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
}
res.getDrawable(R.drawable.e00e)
有关key在xml定义的所有属性,都在Keyboard.java中的key 抽象类中有对应声明;
在API,Values/attrs.xml中;有所有的resources 对应的名称,以及各自属性的声明;通过一次编译后,系统将自动把对应的属性在R.java中生成序列号;
利用TyprArray可以获取每个key各自对应的不同属性;
(: 每页只有当前页的按钮背景不同,当获取key background时,变更改了原先统一的key background; 而当要给每个Key设定新的属性Icon时, 同样在attrs.xml中先声明,再逐个获取 );