Android自定义属性

发布时间:2020-07-16 21:18:02 作者:510202
来源:网络 阅读:557

1   定义属性如下:

    <resources>

    

        <declare-styleable name="social_ivAndTv">

            <attr name="p_w_picpathResource" format="integer" />

            <attr name="title" format="string" />

        </declare-styleable>

    

    </resources>


2 在自定义组件中引用(加粗字体):

        

public ImageViewAndTextView(Context context, AttributeSet attrs) {

super(context, attrs);

     TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.social_ivAndTv);

     resourceId = array.getResourceId(R.styleable.social_ivAndTv_p_w_picpathResource, 0);

     content = array.getString(R.styleable.social_ivAndTv_title);

     initView(context);

}


3 在布局文件中引用:

        3.1在顶部添加命名空间:

                xmlns:app="http://schemas.android.com/apk/res/包名"

        3.2 在自定义组建中添加自定义属性:               

                app:p_w_picpathResource="@drawable/socialweibo_icon_neutral_normal"

                app:title="正面" 


4 完成工作。



推荐阅读:
  1. Android自定义控件之自定义属性 format详解
  2. Android自定义ViewGroup、自定义属性及自定义View

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

android 自定义属性 roi

上一篇:虚拟化网络搭建(标准交换机配置)

下一篇:用vue实现模态框组件

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》