declare-styleable, 自定义属性
来源:互联网 发布:mac gt330m 黑屏 编辑:程序博客网 时间:2024/06/06 00:34
<!-- /* Font Definitions */ @font-face{font-family:宋体;panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-alt:SimSun;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;}@font-face{font-family:"/@宋体";panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:inter-ideograph;mso-pagination:none;font-size:10.5pt;mso-bidi-font-size:12.0pt;font-family:"Times New Roman";mso-fareast-font-family:宋体;mso-font-kerning:1.0pt;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:612.0pt 792.0pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:36.0pt;mso-footer-margin:36.0pt;mso-paper-source:0;}div.Section1{page:Section1;} /* List Definitions */ @list l0{mso-list-id:187108745;mso-list-type:hybrid;mso-list-template-ids:-1117512042 -446148180 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}@list l0:level1{mso-level-tab-stop:18.0pt;mso-level-number-position:left;margin-left:18.0pt;text-indent:-18.0pt;}@list l1{mso-list-id:300119905;mso-list-type:hybrid;mso-list-template-ids:-7276738 234147932 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}@list l1:level1{mso-level-number-format:alpha-lower;mso-level-tab-stop:39.0pt;mso-level-number-position:left;margin-left:39.0pt;text-indent:-18.0pt;text-decoration:underline;text-underline:single;}ol{margin-bottom:0cm;}ul{margin-bottom:0cm;}-->
1. 在LAYOUT文件里定义了控件,如:
<com.motorola.motohome.NewSlidingDrawer
android:id="@+id/drawer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
motohome:topOffset="5px"
motohome:bottomOffset="5px"
motohome:handle="@+id/all_apps"
motohome:content="@+id/content"
motohome:drawable="false"
motohome:gnbcontent="@+id/gnb_bar">
任何其控件下的属性,需要在res/values/attrs.xml中定义
比如android中<resources>
<declare-styleablename="Theme">
<attr name="id"format="reference" />
<attrname="layout_width" format="dimension">
<enumname="fill_parent" value="-1" />
<enum name="wrap_content"value="-2" />
</attr>
比如自定义的MOTOHOME:
<resources>
<declare-styleable name="NewSlidingDrawer">
<!-- Identifier for the child that represents the drawer's handle. -->
<attr name="handle"format="reference" />
<!-- Identifier for the child that represents the drawer's content.-->
<attr name="content" format="reference"/>
<!-- add by fang -->
<attr name="gnbcontent"format="reference" />
<!-- Orientation of the SlidingDrawer. -->
<!-- Extra offset for the handle at the bottom of the SlidingDrawer. -->
<attr name="bottomOffset" format="dimension" />
</declare-styleable>
这样你就可以再控件里引用这个属性,并给他赋值了。
然后你可以在此控件里引用它
TypedArray a =context.obtainStyledAttributes(attrs, R.styleable.NewSlidingDrawer, defStyle, 0);
mDrawable = a.getBoolean(R.styleable.NewSlidingDrawer_drawable, false);
mVertical = (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT);
mBottomOffset = (int) a.getDimension(R.styleable.NewSlidingDrawer_bottomOffset,0);
a. recycle();
以上情况是属于自己定义,自己赋值,另外一种是预先赋值,比如参看下BUTTON代码
public class Button extends TextView {
public Button(Context context) {
this(context, null);
}
public Button(Context context,AttributeSet attrs) {
this(context, attrs,com.android.internal.R.attr.buttonStyle);
}
public Button(Context context,AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
}
用到com.android.internal.R.attr.buttonStyle,从ATTRS.XML文件中找到他
<resources>
<declare-styleable name="Theme">
<attr name="buttonStyle"format="reference" />
在当前目录下找到一个文件THEMES.XML
发现里面有一个定义好的
<style name="Theme">
<itemname="buttonStyle">@android:style/Widget.Button</item>
OK,android自定义的Theme又引用了其他STYLE
再到STYLES中找到
<style name="Widget.Button">
<itemname="android:background">@android:drawable/btn_default</item>
<itemname="android:focusable">true</item>
<itemname="android:clickable">true</item>
<itemname="android:textAppearance">?android:attr/textAppearanceSmallInverse</item>
<itemname="android:textColor">@android:color/primary_text_light</item>
<itemname="android:gravity">center_vertical|center_horizontal</item>
</style>
再次发现android:background属性引用了另外一个DRAWABLE文件
Btn_default
<selectorxmlns:android="http://schemas.android.com/apk/res/android">
<itemandroid:state_window_focused="false"android:state_enabled="true"
android:drawable="@drawable/btn_default_normal" />
<itemandroid:state_window_focused="false"android:state_enabled="false"
android:drawable="@drawable/btn_default_normal_disable" />
<itemandroid:state_pressed="true"
android:drawable="@drawable/btn_default_pressed" />
<itemandroid:state_focused="true" android:state_enabled="true"
android:drawable="@drawable/btn_default_selected" />
<itemandroid:state_enabled="true"
android:drawable="@drawable/btn_default_normal" />
<itemandroid:state_focused="true"
android:drawable="@drawable/btn_default_normal_disable_focused"/>
<item
android:drawable="@drawable/btn_default_normal_disable" />
</selector>
注意,最后在LAYOUT里用到自定义属性时,需要
多加一条
<com.motorola.motohome.DragLayer
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motohome="http://schemas.android.com/apk/res/com.motorola.motohome"
最后要加上包名。
- declare-styleable, 自定义属性
- declare-styleable自定义控件属性
- Android declare-styleable自定义属性
- 自定义控件,自定义控件属性declare-styleable
- declare-styleable:自定义控件的属性
- declare-styleable:自定义控件的属性
- declare-styleable:自定义控件的属性
- declare-styleable:自定义控件的属性
- declare-styleable:自定义控件的属性
- declare-styleable:自定义控件的属性
- declare-styleable的使用,自定义属性值
- declare-styleable:自定义控件的属性
- declare-styleable:自定义控件的属性
- declare-styleable:自定义控件的属性
- 【Android】declare-styleable:自定义控件的属性
- declare-styleable:自定义控件的属性
- declare-styleable:自定义控件的属性
- Android declare-styleable自定义控件属性
- 个人职业提升需要跨越性思维
- layout_weight
- Trace 调试之 noinline 修饰符
- 自动抄表市场漫谈
- XML WebService实例详细解析
- declare-styleable, 自定义属性
- 通俗解释正条件判定覆盖
- 驾校考试秘笈 不用看书就能通过!!
- ashx文件和HttpHandler
- Java Servlet Filter实现Web注销登录过滤器
- 小游戏网站经营之道:站在用户的角度创新
- 一键安装备份3.9(自动卸载加载文件系统管理备份cemail.vol)
- Ubuntu 8.04下编译Android源码全过程
- string.Format字符串格式化说明