您的位置:首页 > 其它

自定义属性引入layout获取不到resourceId的问题

2017-07-07 16:04 375 查看
今天自定义View想达到,能引入layout的效果,例如:

自定义属性:

<declare-styleable name="CustomView"/>
<attr name="empty_layout" format="reference"/>
<declare-styleable>


使用:

<CustomView
android:layout_width="match_parent"
andorid:layout_height="wrap_content"
app:empty_layout="@layout/layout_empty"/>
</CustomView>


但是在自定义View获取自定属性时,拿不到值:

TypeArray typeArray = context.obtainStyleAttributes(R.styleable.CustomView);
int emptyLayoutId = typeArray.getResourceId(R.styleable.CustomView_empty_layout,NO_ID);


原因: 没有传入attr参数

TypeArray typeArray = context.obtainStyleAttributes(attrs,R.styleable.CustomView);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐