当前位置: 代码迷 >> Android >> android namespace 、式样、主题 (二)
  详细解决方案

android namespace 、式样、主题 (二)

热度:65   发布时间:2016-05-01 16:17:59.0
android namespace 、样式、主题 (二)
<?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> 
  相关解决方案