假设app的title 统一的都是这种左中右结构的 代码如下

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/app_title_style"
android:baselineAligned="false"
android:gravity="center_vertical"
android:orientation="horizontal">
<ViewSwitcher
android:id="@+id/app_title_left_switcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/app_title_left_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="返回"/>
<ImageView
android:id="@+id/app_title_left_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</ViewSwitcher>
<ViewSwitcher
android:id="@+id/app_title_middle_switcher"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_marginLeft="16dip"
android:layout_weight="1">
<TextView
android:id="@+id/app_title_middle_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="title"/>
<ImageView
android:id="@+id/app_title_middle_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
</ViewSwitcher>
<ViewSwitcher
android:id="@+id/app_title_right_switcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/app_title_right_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下一步"/>
<ImageView
android:id="@+id/app_title_right_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</ViewSwitcher>
</LinearLayout>

先来继续完善一下BaseActivity

 protected void onCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
ActivityMgr.push(this); findViewById();
} // 初始化app中通用的控件
protected void findViewById(){ }
// 设置标题栏
protected void setTitle(){ }

然后看一下BaseActivity的具体实现类TitleDemoActivity

 public class TitleDemoActivity extendsBaseActivity{  

          protectedvoid onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
} protectedvoid findViewById(){
setContentView(R.layout.title_demo);
super.findViewById();
super.setTitle();// 设置标题栏
}
}

TitleBar封装

BaseActivity的设计初衷是所有的Activity的都继承该类。

首先定义一些通用的属性、以及方法

子类调用

 public class TitleDemoActivity extends BaseActivity {  

     @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); } @Override
protected void findViewById() {
setContentView(R.layout.title_demo);
super.findViewById(); setTitle("返回主页", "这是一个Title", "下一个界面");
} }

android SDK开发 -- TitleBar封装(一)的更多相关文章

  1. Android SDK 开发——发布使用踩坑之路

    前言 在 Android 开发过程中,有些功能是通用的,或者是多个业务方都需要使用的. 为了统一功能逻辑及避免重复开发,因此将该功能开发成一个 SDK 是相当有必要的. 背景 刚好最近自己遇到了类似需 ...

  2. Android SDK开发与使用的那些事儿

    前言 最近由于工作需要,将应用里的部分功能独立了出来,封装成 SDK 提供给合作伙伴使用.由于经验不足,网上也没多少写这方面内容的文章,遇到了不少的坑,决定记录下来. SDK 其实,刚说到要写SDK也 ...

  3. Android SDK 开发指南

    Android SDK 开发指南 视频详解 以下视频是对融云 Android SDK 开发使用的详细讲解,您可以在阅读文档时配合学习.   更多视频教程如下: CSDN 融云 Android SDK ...

  4. 配置Android SDK 开发环境(转)

    1. 下载Eclipse 在前面我们配置好了JDK环境后,就可以开始配置Android的集成开发环境了,官方Google推荐的集成开发环境为Eclipse,所以我们就以Eclipse作为集成开发环境. ...

  5. 基于虹软人证核验 2.0 Android SDK开发集成入门

    一.功能介绍虹软人证核验 2.0 SDK(以下简称SDK)包含人脸检测.人脸跟踪.人证核验等能力,主要实现人证的1:1比对.其中暴露对外的功能方法有:active 引擎激活init 引擎初始化inpu ...

  6. Android SDK开发常用工具的使用及其异常处理

    由于以下操作都是命令操作,所以在执行以下操作之前确保环境变量 ANDROID_HOME 指向的是正确的Android SDK的路径: 一.启动Android SDK Manager: android ...

  7. Google Android SDK开发范例------------20141119

    一.Edit和Checkbox完成对登陆密码的查看:添加Edit的setOnCheckedChageListener和对CheckBox的状态通过isCHecked判断 大体代码如下 CheckBox ...

  8. Google Android SDK开发范例大全笔记 二

    网络设备管理相关相关 代码地址 1 WifiManager LocationManager分别控制 wifi及GPS WifiManager 判断网络状态 ,LocationManager判断定位状态 ...

  9. Google Android SDK开发范例大全笔记 一

    方法讲解 1 获取手机分辨率方法 DisplayMetrics private void getDiaplayMetrics() { DisplayMetrics dm = new DisplayMe ...

随机推荐

  1. oe 仓库管理

    需求情景: 销售电商, 其中有些产品 为代理销售(公司不管理库存,建立SO后直接由对应的供应商发货即可) 解决方案: SO 生成 DO 时候 , 源库存的取得逻辑        SO-->SHO ...

  2. 搭建一个 简易的php版 todolist

    我记得以前使用 wunderlist 但是国外..后来用了半年. 挺方便的.但是.后来慢慢忘了这工具存在 缺少了todolist.效率折半.. so.我搭建了个简单的todolist.  :mytin ...

  3. BZOJ 1143 祭祀

    Description 在遥远的东方,有一个神秘的民族,自称Y族.他们世代居住在水面上,奉龙王为神.每逢重大庆典, Y族都会在水面上举办盛大的祭祀活动.我们可以把Y族居住地水系看成一个由岔口和河道组成 ...

  4. 对ExtJS4应用 性能优化的几点建议

    ExtJS由于UI设计过去强悍,导致性能问题一直被大家诟病,不过到ExtJS4.1之后,性能问题相比以前的版本已有所改善,下面是官方文档给出的优化建议,李坏在此做个小小的总结,仅供大家参考. (1)合 ...

  5. LA3353

    感觉好久没做网络流这类的题目都不快会做了 网络流建模之前首先要分析性质 选择要求每个点恰属一个环就代表每个点在选择的图中,只有唯一入度和唯一出度 那就简单了,对n个点拆点,对于原图的边i-->j ...

  6. bzoj3668

    noi水题,直接推出来每一位上取什么值才能取1直接搞就可以了 ..] of longint; x,n,i,j,k,t,m,ans:longint; fl:boolean; s:string; ch:c ...

  7. BZOJ 1059 [ZJOI2007]矩阵游戏

    1059: [ZJOI2007]矩阵游戏 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2707  Solved: 1322[Submit][Stat ...

  8. OpenSSH远程拒绝服务漏洞

    漏洞版本: OpenSSH 漏洞描述: Bugtraq ID:61286 OpenSSH是一种开放源码的SSH协议的实现 OpenSSH存在一个安全漏洞,允许远程攻击者利用漏洞提交恶意请求,使应用程序 ...

  9. HDOJ 2026 首字母变大写

    Problem Description 输入一个英文句子,将每个单词的第一个字母改成大写字母. Input 输入数据包含多个测试实例,每个测试实例是一个长度不超过100的英文句子,占一行. Outpu ...

  10. 译文链接:http://www.codeceo.com/article/10-truth-programmer-must-know.html

    大多数时候,写代码都是挺有意义的一件事,不光能增加经验值,解决难题的时候还特别爽.耐心.毅力.执着,再加上正确的工具——只要有它们的亲密协作,优雅.漂亮的代码就是手到擒来的事儿. 但是,紧接着拙劣的资 ...