<!-- /* 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-styleable name="Theme">

<attr name="id" format="reference" />

<attr name="layout_width" format="dimension">

<enum name="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">

<item name="buttonStyle">@android:style/Widget.Button</item>

OK,android 自定义的 Theme 又引用了其他 STYLE

再到 STYLES 中找到

<style name="Widget.Button">

<item name="android:background">@android:drawable/btn_default</item>

<item name="android:focusable">true</item>

<item name="android:clickable">true</item>

<item name="android:textAppearance">?android:attr/textAppearanceSmallInverse</item>

<item name="android:textColor">@android:color/primary_text_light</item>

<item name="android:gravity">center_vertical|center_horizontal</item>

</style>

再次发现 android:background 属性引用了另外一个 DRAWABLE 文件

Btn_default

<selector xmlns:android="http://schemas.android.com/apk/res/android">

 <item android:state_window_focused="false" android:state_enabled="true"

android:drawable="@drawable/btn_default_normal" />

 <item android:state_window_focused="false" android:state_enabled="false"

android:drawable="@drawable/btn_default_normal_disable" />

<item android:state_pressed="true"

android:drawable="@drawable/btn_default_pressed" />

<item android:state_focused="true" android:state_enabled="true"

android:drawable="@drawable/btn_default_selected" />

<item android:state_enabled="true"

android:drawable="@drawable/btn_default_normal" />

<item android: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"

最后要加上包名。

更多相关文章

  1. android 定时短信app之时间选择器(一)
  2. Android控件拖拽功能的实现
  3. Android(安卓)中 handle Message 的简单使用笔记
  4. 避免Activity启动时某个控件马上获取焦点(如EditText/Gallery等)
  5. android 动态改变控件位置和大小
  6. adnroid actionbar属性
  7. android 动态改变控件的位置的方法
  8. android属性动画,property animation-android property an
  9. ToolBar左上角一个返回按钮的实现

随机推荐

  1. 如何看待 Kotlin 成为 Android 官方支持
  2. Android异步任务处理框架AsyncTask源码分
  3. 自动搜索私密信息与彻底删除APP--(一)清
  4. Android如何将软键盘回车换成搜索等按钮,E
  5. android培训文档提纲(一)
  6. Android重要组件之一 Service 服务讲解学
  7. Android原生开关组件
  8. android和java平台统一的DES加密解决方案
  9. 应用程序组件之APP基础(转官方)
  10. CMMB在Android平台上的实现步骤简介