您的位置:首页 > 移动开发 > Android开发

android自定义属性

2016-09-27 11:52 281 查看
继上一篇自定义Toolbar过程中,自定义属性的使用

attrs.xml文件中定义自定义的属性GuToolbar,该名称必须与自定义控件的名称一致



自定义控件中使用自定义属性

public GuToolbar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);

initView();
if(attrs != null){
TintTypedArray a = TintTypedArray.obtainStyledAttributes(getContext(), attrs,
R.styleable.GuToolbar, defStyleAttr, 0);
Drawable rightIcon = a.getDrawable(R.styleable.GuToolbar_rightButtonIcon);
if (rightIcon != null) {
setRightBtnIcon(rightIcon);
}
a.recycle();
}
}

布局文件中指定属性的值


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android 自定义属性