android 在布局中使用自定义属性

来源:互联网 发布:淘宝评价好评怎么修改 编辑:程序博客网 时间:2024/05/16 08:59

1.在布局中使用自己的自定义属性的时候,首先要在布局中设置声明:
xmlns:app=”http://schemas.android.com/apk/res-auto”
2.声明完成之后就可以直接使用自己定义的属性了。

<?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-auto"    android:layout_width="match_parent"    android:background="#ffffff"    android:orientation="vertical"    android:layout_height="match_parent">    <!--绘画一个圆形图片-->    <com.zhjy.measureview.CircleView        android:layout_width="wrap_content"        android:background="#000000"        android:layout_margin="20dp"        android:padding="20dp"        app:circle_color="@color/colorAccent"        android:layout_height="100dp" /></LinearLayout>

3.自定义的attrs属性如下:

<?xml version="1.0" encoding="utf-8"?><resources>    <declare-styleable name="CircleView">        <attr name="circle_color" format="color"/>    </declare-styleable></resources>
0 0
原创粉丝点击