你的位置:首页 > 软件开发 > 操作系统 > android复合控件

android复合控件

发布时间:2016-05-08 17:00:08
一.复合控件TopBar 创建复合控件可以很好地创建出具有重用功能的控件集合。比如TopBar。做法:一般需要继承ViewGroup,再给它添加指定功能的控件。 以TopBar为例: 1.自定义属性在values目录下创建attrs.<?<resource ...
一.复合控件TopBar        <attr name="leftTextColor" format="color" />        <attr name="rightTextColor" format="color" />//2.从TypedArray中取出对应的值来为要设置的属性赋值。String mRightText = ta.getString(R.styleable.TopBar_rightText);//3.获取完TypedArray的值后,调用recycle进行资源的回收,避免重新创建的时候的错误。//2.为控件赋值(自定义的属性)mRightButton.setText(mRightText);mTitleView.setText(mTitle);//3.设置布局LayoutParams mRightParams = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.MATCH_PARENT);LayoutParams mTitleParams = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.MATCH_PARENT);mRightButton.setOnClickListener(new OnClickListener() {     @Override    <com.example.geyan.textviewdemo.TopBar        custom:leftBackground="#ffa4c161"        custom:rightBackground="#ffa4c161"        custom:title1="自定义标题"</RelativeLayout>

原标题:android复合控件

关键词:Android

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录