当前位置: 首页 > news >正文

Andorid 自定义标题栏

http://blog.csdn.net/mimitracely/article/details/7968944


先在strings.xml 中定义主题

[html]  view plain copy print ?
  1.    <style name="customTitlebg" >  
  2.     <item name="android:background">@drawable/title_bg</item>  
  3. </style>  
  4.      
  5. <style name="titlebar" parent="android:Theme">  
  6.     <item name="android:windowTitleSize">40dp</item>   
  7.     <item name="android:windowTitleBackgroundStyle">@style/customTitlebg</item>   
  8. </style>  

在AndroidManifest.xml,application标签中改为使用我们自定义的主题

[html]  view plain copy print ?
  1. <application  
  2.         android:icon="@drawable/ic_launcher"  
  3.         android:label="@string/app_name"  
  4.         android:theme="@style/titlebar" >  
  5.         <activity  
  6.             android:name=".MainActivity"  
  7. ...  

下面是自定义标题栏的实现 title_bar.xml

[html]  view plain copy print ?
  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"   
  3.     android:orientation="horizontal" android:layout_width="fill_parent"   
  4.     android:layout_height="fill_parent">  
  5.     <ImageView android:layout_width="wrap_content"   
  6.         android:layout_centerVertical="true"  
  7.         android:layout_height="wrap_content"   
  8.         android:src="@drawable/title_home_normal" />  
  9.       
  10.     <TextView android:layout_width="wrap_content"   
  11.         android:layout_centerInParent="true"   
  12.         android:layout_height="wrap_content"   
  13.         android:textColor="#000000"  
  14.         android:text="自定义标题栏" />  
  15.   
  16.     <ImageView  
  17.         android:layout_width="wrap_content"  
  18.         android:layout_height="wrap_content"  
  19.         android:layout_alignParentRight="true"  
  20.         android:layout_centerVertical="true"  
  21.         android:src="@drawable/title_new_normal" />  
  22.   
  23. </RelativeLayout>  
最后修改Activity
[java]  view plain copy print ?
  1. public void onCreate(Bundle savedInstanceState) {  
  2.     super.onCreate(savedInstanceState);  
  3.     requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); //声明使用自定义标题   
  4.     setContentView(R.layout.tabhost);  
  5.     getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);//自定义布局赋值   
  6. }  


转载于:https://www.cnblogs.com/zsw-1993/archive/2012/09/27/4880839.html

相关文章:

  • S2JDBC テーブルを利用した独自仕様のid採番メソッド
  • Qt学习之路(54): 自定义拖放数据对象
  • 创建 Silverlight 应用程序以访问 SharePoint 2010 数据
  • Qt学习之路(53): 拖放技术之二
  • OPPM 一页纸项目管理 One-Page Project Management
  • Qt学习之路(52): 拖放技术之一
  • C# 图片识别(支持21种语言)【转】
  • Qt学习之路(tip): Qt容器和算法拾遗
  • 使用 vimdiff 來呈現 Git diff 差異
  • android 开发Eclipse 快捷键
  • Qt学习之路(51): QByteArray和QVariant
  • 我该如何奋斗?
  • Qt学习之路(50): QString
  • 原创:C语言贪吃蛇代码
  • Qt学习之路(49): 通用算法
  • [ 一起学React系列 -- 8 ] React中的文件上传
  • 【140天】尚学堂高淇Java300集视频精华笔记(86-87)
  • Android单元测试 - 几个重要问题
  • android高仿小视频、应用锁、3种存储库、QQ小红点动画、仿支付宝图表等源码...
  • angular组件开发
  • Apache Pulsar 2.1 重磅发布
  • - C#编程大幅提高OUTLOOK的邮件搜索能力!
  • centos安装java运行环境jdk+tomcat
  • el-input获取焦点 input输入框为空时高亮 el-input值非法时
  • IOS评论框不贴底(ios12新bug)
  • javascript数组去重/查找/插入/删除
  • JavaScript异步流程控制的前世今生
  • JAVA并发编程--1.基础概念
  • Java-详解HashMap
  • JSDuck 与 AngularJS 融合技巧
  • oldjun 检测网站的经验
  • Spring Cloud Alibaba迁移指南(一):一行代码从 Hystrix 迁移到 Sentinel
  • 不用申请服务号就可以开发微信支付/支付宝/QQ钱包支付!附:直接可用的代码+demo...
  • 从@property说起(二)当我们写下@property (nonatomic, weak) id obj时,我们究竟写了什么...
  • 从setTimeout-setInterval看JS线程
  • 聊聊flink的BlobWriter
  • 设计模式(12)迭代器模式(讲解+应用)
  • 什么软件可以提取视频中的音频制作成手机铃声
  • 使用Tinker来调试Laravel应用程序的数据以及使用Tinker一些总结
  • 新手搭建网站的主要流程
  • 正则表达式
  • 函数计算新功能-----支持C#函数
  • ​虚拟化系列介绍(十)
  • #我与Java虚拟机的故事#连载04:一本让自己没面子的书
  • #中国IT界的第一本漂流日记 传递IT正能量# 【分享得“IT漂友”勋章】
  • (2)Java 简介
  • (3)nginx 配置(nginx.conf)
  • (安卓)跳转应用市场APP详情页的方式
  • (独孤九剑)--文件系统
  • (附源码)spring boot公选课在线选课系统 毕业设计 142011
  • (附源码)ssm高校志愿者服务系统 毕业设计 011648
  • (附源码)ssm失物招领系统 毕业设计 182317
  • (含react-draggable库以及相关BUG如何解决)固定在左上方某盒子内(如按钮)添加可拖动功能,使用react hook语法实现
  • (理论篇)httpmoudle和httphandler一览
  • (利用IDEA+Maven)定制属于自己的jar包