安卓自定义View

来源:互联网 发布:传奇网络 编辑:程序博客网 时间:2024/05/16 15:25

attrs.xml 详解

我们在使用组件属性的时候经常会使用

android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="减少分数" 

这些都是系统属性,我们通过attrs.xml可以自己定义属性

<?xml version="1.0" encoding="utf-8"?><resources>    //自定义属性名,定义公共属性    //name=“样式属性名称” format="样式类型如:String、int、color等"    <attr name="titleSize" format="dimension"></attr>    <attr name="titleText" format="string"></attr>    <attr name="titleColor" format="color"></attr>    <attr name="outCircleColor" format="color"></attr>    <attr name="inCircleColor" format="color"></attr>    <attr name="lineColor" format="color"></attr>    //自定义控件的主题样式    //MySportView样式名称    <declare-styleable name="MySportView">        <attr name="titleSize"></attr>        <attr name="titleText"></attr>        <attr name="titleColor"></attr>        <attr name="outCircleColor"></attr>        <attr name="inCircleColor"></attr>    </declare-styleable>    <declare-styleable name="MyQQHealthView">        <attr name="titleColor"></attr>        <attr name="lineColor"></attr>    </declare-styleable></resources>
11 0
原创粉丝点击