<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.namespace"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.namespace.MyView
xmlns:name="http://venus585625.iteye.com/admin" android:id="@+id/myview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:textColor="#FFFFFFFF"
app:textSize="40dip"
app:textPaddingLeft="40dip"
app:textPaddingTop="40dip"
app:imgBackground="@drawable/icon"
name:back="@drawable/icon"
name:textSize="32.4"/>
</LinearLayout>
对于上面这XML描述中,name:textSize="32.4" ,在java代码中
float srcSize = attrs.getAttributeFloatValue(NAMESPACE, "textSize", 10.0f);用如此解析这些值,因为这个textSize没有在attrs.xml里面进行定义,
TypedArray params = context.obtainStyledAttributes(attrs,
R.styleable.MyView);
这个params里面并不包含这个textSize.



注意在附件中有一个style。
在value下面创建一个文件styles.xml

<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="MyView" parent="android:Widget">
<item name="android:background">#FFFFFFFF</item>
<item name="textColor">#FFFF0000</item>
</style>
</resources>

更多相关文章

  1. Android高手进阶教程(二十七)之---基于ViewFlipper实现的自定义
  2. Android 中自定义View的应用
  3. Android 自定义键盘中禁用点击预览弹窗
  4. android-控件样式(Theme)自定义
  5. android button 自定义
  6. android实现ios形式的字体,实现各种自定义的字体
  7. Android自定义对话框(Custom Dialog)
  8. 自定义adapter 及其性能优化

随机推荐

  1. Android(安卓)生成keystore,两种方式
  2. android 打包 eclipse 错误 Export abort
  3. Android(安卓)Volley 库通过网络获取 JSO
  4. 强制结束Android进程
  5. android 解析json数据格式
  6. android GestureOverlayView
  7. 【Android】数据存储之SQLite
  8. Android(安卓)模仿QQ空间风格的 UI
  9. Suggestion: add 'tools:replace="androi
  10. Android开机广播和关机广播