创建自定义控件
2015-11-29 14:26
260 查看
1.在layout目录下创建title.xml:
2.新建ownui包创建titleView.java:
<?xml version="1.0" encoding="utf-8"?> <!-- 自建伪标题ActionBar --> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="50dp" android:background="@android:color/holo_green_dark"> <ImageView android:id="@+id/img_title" android:layout_width="50dp" android:layout_height="50dp" android:layout_marginLeft="7dp" android:scaleType="fitXY" android:src="@drawable/ic_launcher"/> <TextView android:id="@+id/tv_title" android:layout_width="wrap_content" android:layout_height="50dp" android:layout_marginLeft="5dp" android:layout_marginTop="15dp" android:layout_toRightOf="@id/img_title" android:text="@string/title_tv"/> <Button android:id="@+id/btn_title" android:layout_width="60dp" android:layout_height="50dp" android:layout_alignParentRight="true" android:layout_marginRight="7dp" android:text="@string/title_settings"/> </RelativeLayout>
2.新建ownui包创建titleView.java:
/** * 创建自定义控件 */ public class TitleLayout extends Layout { public TitleLayout(Context context, AttributeSet attrs) { super(context, attrs); LayoutInflater.from(context).inflate(R.layout.title, this);//TODO 填充xml Button btnTitle = (Button) findViewById(R.id.btn_title); if(getContext() instanceof MainActivity)//判断一个对象是否是指定类型的实例对象 { btnTitle.setText(R.string.title_settings); } } }
相关文章推荐
- unbuntu server12.04配置hadoop2.7.1(四):hadoop 2.7.1的安装(所有2.x版本都可以)
- LintCode-剑指Offer-(46)主元素
- UITextView的常用方法
- 前端性能优化 CSS动画
- [LeetCode]Binary Tree Level Order Traversal II
- JavaWeb-结合七牛搭建个人相册
- Ubuntu Server VMWare Install
- ibatis的简单入门
- 2015年11月 广州深圳 MVP 线下活动
- Linux终端的总结和shell
- POJ1840 Eqr (哈希)
- Fragment生命周期方法的说明
- Ping使用
- framebuffer 子系统分析
- [Sort]堆排序
- 如何打开A20地址线的方法
- 微信多客服开发
- 将.mdf和_log.ldf的文件添加到Microsoft SQL Server的方法
- RISC 、 CISC 和 ARM处理器
- Webkit之平台相关层