android namespace 、样式、主题 (二)
16lz
2021-12-04
<?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(安卓)上使用 XML
- android 获取图片
- 2011.09.22——— android ViewStub的简单使用
- Android(安卓)触摸事件传递流程解析
- Android(安卓)ApiDemos示例解析(100):Views->Auto Complete->2.
- CMAKE 在Linux下 构建android 编译、打包、发布环境
- 2013.05.16——— android 关于listview的bug
- 2011.09.22——— android ViewStub的简单使用
- Android(安卓)O版本Call对象解析