android namespace 、样式、主题 (二)
16lz
2021-01-23
<?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>
<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>
更多相关文章
- Android高手进阶教程(二十七)之---基于ViewFlipper实现的自定义
- Android 中自定义View的应用
- Android 自定义键盘中禁用点击预览弹窗
- android-控件样式(Theme)自定义
- android button 自定义
- android实现ios形式的字体,实现各种自定义的字体
- Android自定义对话框(Custom Dialog)
- 自定义adapter 及其性能优化