自定义属性引入layout获取不到resourceId的问题
2017-07-07 16:04
375 查看
今天自定义View想达到,能引入layout的效果,例如:
自定义属性:
使用:
但是在自定义View获取自定属性时,拿不到值:
原因: 没有传入attr参数
自定义属性:
<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);
相关文章推荐
- 【android学习笔记】自定义Adapter继承BaseAdapter获取不到getview或者getview不执行的问题
- Android开发——通过使用getResource.getIdentifier() 获取layout中组件id
- 单元测试获取不到配置文件自定义配置的问题解决方法
- 【android学习笔记】自定义Adapter继承BaseAdapter获取不到getview或者getview不执行的问题
- 解决form中action属性后面?传递参数 获取不到的问题
- 微信小程序获取不到unionid还有小程序无法解析JSON字符串的问题
- 关于自定义的data-*属性有时候取不到值的问题
- 【android学习笔记】自定义Adapter继承BaseAdapter获取不到getview或者getview不执行的问题
- 一例应用Microsoft.AspNet.Identity初始化角色权限导致的UserManager.GetRoles(user.Id)始终获取不到账号角色问题的解决
- Android布局问题: No resource found that matches the given name (at 'layout_above' with value @id/tv)
- 关于JS获取不到动态创建的元素的id的问题
- TextBox属性设置为只读后台获取不到值的问题
- Remoting中,关于获取某接口派生的自定义属性(CustomAttribute)的问题
- Jquery根据id获取属性的一个奇怪问题
- 关于js获取不到客户端控件id的问题【搜藏】
- 关于自定义的data-*属性有时候取不到值的问题 2
- jq获取h5的自定义data-属性的问题
- 关于RemoteView构造函数中layoutId布局的根节点必须含有layout_width属性问题
- iOS问题笔记-[[NSBundle mainBundle] pathForResource: ofType:]方法获取不到资源路径
- Android 通过resource名称或者layout中定义的id name 去获取R.java中id,得到控件