招标网站都有哪些,济宁网站建设_云科网络,建设特效网站,微信运营包括哪些内容波斯汪是的#xff0c;有一种方法#xff1a;假设您有一个小部件的属性声明(在中attrs.xml)#xff1a; 声明用于样式参考的属性(在中attrs.xml)#xff1a; 为小部件声明一组默认属性值(在中styles.xml)#xff1a;声明自定义主题(在中themes.xml)#xff1a;将此…波斯汪是的有一种方法假设您有一个小部件的属性声明(在中attrs.xml) 声明用于样式参考的属性(在中attrs.xml) 为小部件声明一组默认属性值(在中styles.xml)声明自定义主题(在中themes.xml)将此属性用作窗口小部件的构造函数中的第三个参数(在中CustomImageButton.java)public class CustomImageButton extends ImageButton { private String customAttr; public CustomImageButton( Context context ) { this( context, null ); } public CustomImageButton( Context context, AttributeSet attrs ) { this( context, attrs, R.attr.customImageButtonStyle ); } public CustomImageButton( Context context, AttributeSet attrs, int defStyle ) { super( context, attrs, defStyle ); final TypedArray array context.obtainStyledAttributes( attrs, R.styleable.CustomImageButton, defStyle, R.style.Widget_ImageButton_Custom ); // see below this.customAttr array.getString( R.styleable.CustomImageButton_customAttr, ); array.recycle(); }}现在您必须应用Theme.Custom到所有使用的活动CustomImageButton(在AndroidManifest.xml中)就这样。现在CustomImageButton尝试从customImageButtonStyle当前主题的属性加载默认属性值。如果在主题或属性的值中未找到此类属性nullobtainStyledAttributes则将使用的最后一个参数Widget.ImageButton.Custom在这种情况下。您可以更改所有实例和所有文件的名称(除外AndroidManifest.xml)但是使用Android命名约定会更好。