html 添加窗口小部件,如何:为自定义窗口小部件定义主题(样式)项
波斯汪
是的,有一種方法:假設您有一個小部件的屬性聲明(在中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當前主題的屬性加載默認屬性值。如果在主題或屬性的值中未找到此類屬性@null,obtainStyledAttributes則將使用的最后一個參數:Widget.ImageButton.Custom在這種情況下。您可以更改所有實例和所有文件的名稱(除外AndroidManifest.xml),但是使用Android命名約定會更好。
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的html 添加窗口小部件,如何:为自定义窗口小部件定义主题(样式)项的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java与MySQL做购物系统_java
- 下一篇: java 包含汉字,java判断字符串中