假设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. 利用Python读取Matlab的Mat文件内容

    手头有别人写的Matlab程序,其中用到了Mat文件.现在不想安装Matlab,却又想读取Mat文件内容,该怎么办呢? 感谢scipy!!! import scipy.io data = scipy. ...

  2. 项目知识点.Part2

    1. 取消collectionView头视图重叠情况:以下两种情况效果一样 但是有一点点bug 每次remove之后 需要把视图刷到上面才会显示(后续会改进方法) for (UIView *view ...

  3. vim操作命令-笔记

    显示行号:在vim命令行模式下输入 :set nu 或 :set number 取消显示行号:在vim命令行模式下输入 :set nonu 或 :set nonumber 查看文件编码格式: :set ...

  4. ps中常用的快捷键

    ctrl+c  复制 ctrl+v 粘贴 ctrl+n 新建文件 ctrl+s 保存 空格键   手抓工具 ctrl+t  自由变形 ctrl+加号  放大 ctrl+减号  缩小 ctrl+r  标 ...

  5. yum命令常见方法

    yum check-update 检查可更新的所有软件包 yum update 下载更新系统已安装的所有软件包 yum upgrade 大规模的版本升级,与yum update不同的是,连旧的淘汰的包 ...

  6. 数据结构(动态树):UOJ 207 共价大爷游长沙

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABHwAAAJZCAIAAABUW7XHAAAgAElEQVR4nOy93cstx5Xm2f9TXh2EOe

  7. 黄源河《左偏树的应用》——数字序列(Baltic 2004)

    这道题哪里都找不到. [问题描述] 给定一个整数序列a1, a2, … , an,求一个不下降序列b1 ≤ b2 ≤ … ≤ bn,使得数列{ai}和{bi}的各项之差的绝对值之和 |a1 - b1| ...

  8. 【动态规划】Codeforces 711C Coloring Trees

    题目链接: http://codeforces.com/problemset/problem/711/C 题目大意: 给N棵树,M种颜色,已经有颜色的不能涂色,没颜色为0,可以涂色,每棵树I涂成颜色J ...

  9. select的使用(二)

    多表查询 /*基本连接*/ select a.Name,b.Name from T_Employee a,T_Department b where a.DepartmentId=b.Id /*内连接, ...

  10. OpenGL图形管线和坐标变换

    转:http://blog.csdn.net/zhulinpptor/article/details/5897102 1. OpenGL 渲染管线 OpenGL渲染管线分为两大部分,模型观测变换(Mo ...