自定义View---自定义Title InvalidInt:res/drawable xxhdpi-v4/arrow_back.png

本文介绍了如何自定义一个View,继承自RelativeLayout,并在Android中设置自定义属性。在自定义属性时,强调了在res/values/attr.xml中定义属性的重要性。错误地使用了getInt()方法来获取图片资源,而应使用getDrawable()方法来获取Drawable对象,然后用Imageview的setImageDrawable()方法设置图片。
摘要由CSDN通过智能技术生成

1.建立一个类,继承RelativeLayout

2.写好布局

3.在res/values/attr.xml 中自定义其属性

5.在class中实例化自定义属性、布局控件


在eclipse中需要将声明自定义view 跟属性的格式分开

studio中是可以一起写的

<resources>
<span style="white-space:pre">	</span><!--name 对应的定义属性,format 就是属性值的格式 -->
    <attr name="title_text" format="string" />
    <attr name="title_leftimg" format="reference" />
    <attr name="title_size" format="dimension" />
    <attr name="title_color" format="color" />
<span style="white-space:pre">	</span><!--声明这个 自定义view,name一般用class名,下面的attr标签就是定义的属性 -->
    <declare-styleable name="CustomTitleView">
        <attr name="title_text" />
        <attr name="title_leftimg" />
        <attr name="title_size" />
        <attr name="title_color" />
    </declare-styleable>
</resources>
下面是从网上copy别人的一些format格式对应的意思

reference   表示引用,参考某一资源ID 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值