假设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. SVN允许修改日志

    1.强制写日志在每次提交的时候写明提交的目的是一个很好的习惯,Subversion默认没有提供,但是可以通过钩子实现:将下面的代码存为放到版本库的hooks目录下即可,当你不写日志提交的话就会报告错误 ...

  2. Java中传参的值传递和引用传递问题(转)

    今天遇到了一个java程序,需要用参数来返回值(虽然最后用另一种方法实现了),在网上看到这样一篇文章,很受启发. 本文章来自于http://hi.baidu.com/xzhilie/blog/item ...

  3. Linux下软件的安装

    想必linux新手刚开始对于linux软件安装很茫然吧,不知到怎么安装,软件到底安装在哪里,如果我需要删除软件怎么删除,配置文件到哪里去找. 想学习linux的话,最快上手的应该是Ubuntu,它特有 ...

  4. 求解:远程方法调用失败Exception from HRESULT: 0x800706BE)

    服务器:Windows Server2003 sp2服务器 客户端:XP SP3 内容:C#Winform客户端调用服务器的Excel模板生成报表的时候,生成失败,抛出的异常如下: TargetInv ...

  5. jQuery.dialog

    本篇文章主要是对JQUERY中dialog的用法进行了详细的分析介绍,需要的朋友可以过来参考下,希望对大家有所帮助 今天用到了客户端的对话框,把 jQuery UI 中的对话框学习了一下. 准备 jQ ...

  6. Google Cardboard

    Google Cardboard是谷歌的一个虚拟现实开源项目,旨在使用户可以以一种简单.有趣且廉价的方式体验虚拟现实.用户只需要在Android手机上安装一个Google Cardboard应用,并将 ...

  7. RichEdit中插入带背景色文本的一种思路

    uses RichEdit; function TextToRtf( // 将文本处理为RTF格式 mText: WideString // 输入文本 ): WideString; // 返回处理后的 ...

  8. 通过PHP连接MYSQL数据库 创建数据库 创建表

    通过PHP连接MYSQL数据库  $conn = mysql_connect("localhost","root","password") ...

  9. ftp上传下载脚本

    #!/usr/bin/env python #encoding=utf-8 # @Date: 2015-08-10 import datetime from ftplib import FTP &qu ...

  10. Delphi TdxComponentPrinter页头页脚的设定

    TdxComponentPrinter页头页脚的设定 抄一段备忘.用程序控制也一样.如果是这样,那么 双击TdxComponentPrinter控件,在出现的窗口中,点击ADD,建立一个与TcxGri ...