自定义控件之--组合控件(titlebar)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rl_top"
android:layout_width="fill_parent"
android:layout_height="@dimen/top_height"
android:background="#f8f8f8" >
<Button
android:id="@+id/btn_top_back"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:gravity="center"
android:background="@drawable/btn_top_back"
android:textSize="20sp" />
<TextView
android:id="@+id/tv_top_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="@string/app_name"
android:textColor="@color/black"
android:textSize="20sp" />
<Button
android:id="@+id/btn_top_right"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="@dimen/image_corner_radius"
android:background="@null"
android:gravity="center"
android:textColor="@drawable/btn_top_right_selector"
android:textSize="16sp" />
<TextView
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:layout_height="1dp"
android:background="@color/gray" />
</RelativeLayout>
public class TitleView extends FrameLayout {
private Button btn_top_back;
private TextView tv_top_title;
private Button btn_top_right;
public TitleView(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.common_top, this);
btn_top_back = (Button) findViewById(R.id.btn_top_back);
tv_top_title = (TextView) findViewById(R.id.tv_top_title);
btn_top_right = (Button) findViewById(R.id.btn_top_right);
}
public void setvisible(int left,int middle,int right){
btn_top_back.setVisibility(left);
tv_top_title.setVisibility(middle);
btn_top_right.setVisibility(right);
}
public void setTitle(String title){
tv_top_title.setText(title);
}
public void setLeftOnclickListener(OnClickListener onClickListener){
btn_top_back.setOnClickListener(onClickListener);
}
public void setRightOnclickListener(OnClickListener onClickListener){
btn_top_right.setOnClickListener(onClickListener);
} public void setRightText(String text){
btn_top_right.setText(text);
}
}在布局里面就可以通过包名+类名来重用title布局文件,在activity或者fragement里面初始化,通过TitleView的方法控制内容的显示和隐藏,以及内容的变化,控件事件的响应。
自定义控件之--组合控件(titlebar)的更多相关文章
- Android开发技巧——自定义控件之组合控件
Android开发技巧--自定义控件之组合控件 我准备在接下来一段时间,写一系列有关Android自定义控件的博客,包括如何进行各种自定义,并分享一下我所知道的其中的技巧,注意点等. 还是那句老话,尽 ...
- Flutter学习笔记(38)--自定义控件之组合控件
如需转载,请注明出处:Flutter学习笔记(38)--自定义控件之组合控件 在开始之前想先写点其他的,emm...就是今天在学习到自定义控件的时候,由于自定义控件这块一直是我的短板,无论是Andro ...
- android--------自定义控件 之 组合控件篇
上篇介绍了自定义控件的自定义属性篇,地址:http://www.cnblogs.com/zhangqie/p/8969163.html 这篇博文主要来说说 自定义控件的组合控件来提高布局的复用 使用自 ...
- Android自定义控件之自定义组合控件
前言: 前两篇介绍了自定义控件的基础原理Android自定义控件之基本原理(一).自定义属性Android自定义控件之自定义属性(二).今天重点介绍一下如何通过自定义组合控件来提高布局的复用,降低开发 ...
- Android自定义控件之自定义组合控件(三)
前言: 前两篇介绍了自定义控件的基础原理Android自定义控件之基本原理(一).自定义属性Android自定义控件之自定义属性(二).今天重点介绍一下如何通过自定义组合控件来提高布局的复用,降低开发 ...
- Andriod 自定义控件之创建可以复用的组合控件
前面已学习了一种自定义控件的实现,是Andriod 自定义控件之音频条,还没学习的同学可以学习下,学习了的同学也要去温习下,一定要自己完全的掌握了,再继续学习,贪多嚼不烂可不是好的学习方法,我们争取学 ...
- ASP.NET自定义控件组件开发 第四章 组合控件开发CompositeControl
原文:ASP.NET自定义控件组件开发 第四章 组合控件开发CompositeControl 第四章 组合控件开发CompositeControl 大家好,今天我们来实现一个自定义的控件,之前我们已经 ...
- ASP.NET自定义控件组件开发 第四章 组合控件开发CompositeControl 后篇 --事件冒泡
原文:ASP.NET自定义控件组件开发 第四章 组合控件开发CompositeControl 后篇 --事件冒泡 CompositeControl 后篇 --事件冒泡 系列文章链接: ASP.NET ...
- Android自定义控件View(三)组合控件
不少人应该见过小米手机系统音量控制UI,一个圆形带动画效果的音量加减UI,效果很好看.它是怎么实现的呢?这篇博客来揭开它的神秘面纱.先上效果图 相信很多人都知道Android自定义控件的三种方式,An ...
随机推荐
- 在windows下安装pip scrapy...
将 C:\Users\用户名\AppData\Local\Programs\Python\Python35\Scripts C:\Users\用户名\AppData\Local\Programs\Py ...
- html 页面太长滚动时,固定页面菜单标签,或者导航标签的位置,fixed/stickUp the position
有时你曾经需要把页面上的某些东西当页面太长发滚动的时候保留置顶位置显示,或许你有别的实现方式,我这个仅供参考, 源代码: /*global $, jQuery, alert*/ (function ( ...
- rhel7.2 yum
redhat 的更新包只对注册的用户生效,所以我们自己手动更改成CentOS 的更新包,CentOS几乎和redhat是一样的,所以无需担心软件包是否可安装,安装之后是否有问题. (前提是wget包已 ...
- python_实现_斐波那契额函数
在学递归的时候,用递归实现了一个 下面是代码 def fib(n): if n >= 3: return fib(n-1)+fib(n-2) else: return 1 print(fib(6 ...
- ubuntu 10.4非法关机后上不了网
用的好好的ubuntu 10.4,非法关机后居然上不了网,右上角的网络图标也不见了,还以为是网卡问题,进入xp,发现一切正常,心里不断地诅咒ubuntu,该死的ubuntu,我windows还天天非法 ...
- hdu 3631 Shortest Path
floyd算法好像很奇妙的样子.可以做到每次加入一个点再以这个点为中间点去更新最短路,效率是n*n. #include<cstdio> #include<cstring> #i ...
- 2016年团体程序设计天梯赛-决赛 L2-3. 互评成绩(25)
学生互评作业的简单规则是这样定的:每个人的作业会被k个同学评审,得到k个成绩.系统需要去掉一个最高分和一个最低分,将剩下的分数取平均,就得到这个学生的最后成绩.本题就要求你编写这个互评系统的算分模块. ...
- PAT 团体程序设计天梯赛-练习集 L1-019. 谁先倒
给出甲.乙两人的酒量(最多能喝多少杯不倒)和划拳记录,请你判断两个人谁先倒. 输入格式: 输入第一行先后给出甲.乙两人的酒量(不超过100的非负整数),以空格分隔.下一行给出一个正整数N(<=1 ...
- Java Swing 日期控件(转载)
http://www.cnblogs.com/lzy1991/p/5714935.html
- Effective JavaScript :第一章
第一章 一.严格模式与非严格模式 1.在程序中启用严格模式的方式是在程序的最开始增加一个特定的字符串字面量: ‘use strict’ 同样可以在函数体的开始处加入这句指令以启用该函数的严格模式. f ...