(转)Android 自定义标题栏(title栏)
转:http://blog.csdn.net/jamin0107/article/details/6715678
第一步,向实现自定义标题栏,需要在onCreate方法里这样写
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
注意:
requestWindowFeature要在setContentView之前
etWindow().setFeatureInit最好在setContentView之后
第二步,就是写好自己的布局文件,实现标题栏的自定义。
不过我们会遇到一些问题,就是标题栏的高度不能自定义~下面就是解决办法~

下面,我们看一下android title标题栏 在源码 framework中的XML文件
screen_custom_title.xml
<LinearLayout android:orientation="vertical" android:fitsSystemWindows="true">
<FrameLayout android:id="@android:id/title_container"
android:layout_width="match_parent"
android:layout_height="?android:attr/windowTitleSize"
style="?android:attr/windowTitleBackgroundStyle">
</FrameLayout>
<FrameLayout android:id="@android:id/content"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:foregroundGravity="fill_horizontal|top"
android:foreground="?android:attr/windowContentOverlay"/>
</LinearLayout>
screen_title.xml
<LinearLayout android:orientation="vertical" android:fitsSystemWindows="true">
−
<FrameLayout android:layout_width="match_parent"
android:layout_height="?android:attr/windowTitleSize"
style="?android:attr/windowTitleBackgroundStyle">
<TextView android:id="@android:id/title"
style="?android:attr/windowTitleStyle"
android:background="@null"
android:fadingEdge="horizontal"
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
<FrameLayout android:id="@android:id/content"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:foregroundGravity="fill_horizontal|top"
android:foreground="?android:attr/windowContentOverlay"/>
</LinearLayout>
既然是自定义标题,那我们就看screen_custom_title.xml,里面有一个title_container和一个content,组合成了标题栏,我们自定义标题所给出的view,都被content作为子view了,影响不了那个title_container和content,所以,任你怎么弄,它该留白的还是留白,你没招。
看title_container有个style是这样的:
style="?android:attr/windowTitleBackgroundStyle"
content的foreground是这样的android:foreground="?android:attr/windowContentOverlay"
我们可以自己写一个style
<resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="CustomWindowTitleBackground">
<item name="android:background">#00cc00</item>
</style> <style name="title_bar" parent="android:Theme">
<item name="android:windowTitleSize">50dp</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
加入到AndroidManifest
<activity android:name=".CustomTitileBarActivity"
android:label="@string/app_name" android:theme="@style/title_bar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

PS:做的略显粗糙,不过以能实现功能为主
(转)Android 自定义标题栏(title栏)的更多相关文章
- [置顶]
xamarin android自定义标题栏(自定义属性、回调事件)
自定义控件的基本要求 这篇文章就当是自定义控件入门,看了几篇android关于自定义控件的文章,了解了一下,android自定义控件主要有3种方式: 自绘控件:继承View类,所展示的内容在OnDra ...
- Android 自定义标题栏
开发 Android APP 经常会用到自定义标题栏,而有多级页面的情况下还需要给自定义标题栏传递数据. 本文要点: 自定义标题填充不完整 自定义标题栏返回按钮的点击事件 一.代码 这里先介绍一下流程 ...
- setFeatureInt、android 自定义标题栏
Android 自带的toolbar 往往不能很好的的满足我们的个性化要求.因此我们经常使用自定的的标题栏.而Android系统本身也允许我们自定以标题栏. 记录一下,自定义标题栏常遇到的问题.先上效 ...
- Android -- 自定义标题栏,背景颜色填充满
设置标题栏背景 1> 准备背景图片: background_pix.png 注:用背景图片比用颜色好处,可以让背景看起来有凹凸感. 2> drawable文件夹下放xml文件 bitmap ...
- Android自定义标题栏
预览一下效果: 素材: 新建一个布局title_bar.xml,代码如下: <?xml version="1.0" encoding="utf-8"?&g ...
- android 自定义标题栏 titleBar自定义
在value文件夹下添加style.xml <?xml version="1.0" encoding="utf-8"?> <resources ...
- Android—自定义标题栏的实现及遇见的问题解决
开发者设计界面时候往往不会使用系统自带的标题栏,因为不美观,所以需要自己设置标题栏. 1.根据需求在xml文件中设置标题布局 <?xml version="1.0" enco ...
- 【起航计划 006】2015 起航计划 Android APIDemo的魔鬼步伐 05 App->Activity->Custom Title 自定义标题栏
Android UI缺省的标题栏由android:label 定义,显示在屏幕左上角,Android允许Activity自定义标题栏,使用自定义Layout重新设置标题栏,比如实现Windows Mo ...
- android全屏去掉title栏的多种实现方法
android全屏去掉title栏的多种实现方法 作者: 字体:[增加 减小] 类型:转载 时间:2013-02-18我要评论 android全屏去掉title栏包括以下几个部分:实现应用中的所有ac ...
随机推荐
- who - 显示已经登录的用户
总览 (SYNOPSIS) who [OPTION]... [ FILE | ARG1 ARG2 ] 描述 (DESCRIPTION) -H, --heading 显示 栏目行 -i, -u, --i ...
- 压缩与解压缩 gzip bzip2 tar 命令
gzip压缩与解压缩 命令 gzip -v 解压缩 gzip-d 操作如下. 压缩 .可以看到源文件有5171大小,压缩后,变成了1998大小. 解压缩 .解压缩之后可以看到,原来的man_db ...
- mui框架页面每次加载操作
最近在优化自己用mui开发的app,主要还是针对交互这块儿,这里简单给大家说一下问题点场景,就是我是通过动态添加底部tabBar的方法创建了一个底部可以切换的操作区域,代码如下: mui.init() ...
- 【SPOJ DQUERY】区间数字统计
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 因为区间的端点移动一个单位的话,只会涉及到一个元素的增多或减少. 因此可以用莫队算法来解决. 只需要开一个数组(大小1百万),用下标来快速检索 ...
- Python self的用法
1)不加self是局部变量,只在这个方法里有效:加self则是实例变量,相当于别的函数定义的变量你实例化出来就可以使用 #coding:utf-8 class Person: def __init__ ...
- fabric.js 限制缩放的最大最小比例
var rect = new fabrics.Rect({ v: true, top: 216, left: 384, width: 160, height: 90, fill: 'transpare ...
- mysql函数操作-增加自定义函数
#首先执行看mysql是否开启函数SHOW VARIABLES LIKE '%func%';------------------------------------------------------ ...
- 牛客多校第九场 B Quadratic equation 模平方根
题意: 已知 $x+y$ $mod$ $q = b$ $x*y$ $mod$ $q = c$ 已知b和c,求x和y 题解: 容易想到$b^2-4c=x^2-2xy+y^2=(x-y)^2$ 那么开个根 ...
- 秦曾昌人工智能课程---6、Decision Tree Learning
秦曾昌人工智能课程---6.Decision Tree Learning 一.总结 一句话总结: 怎样去构建决策树:比如一维:***|00|***|000|***,|为分割线,每个分割点都是一种情况, ...
- access数据库调用
1.工程环境配置(vs+qt) 点击项目,右键,选择项目设置,选择SQL 2.获取自己数据库的驱动版本有哪些,如下代码所示: QStringList drivers = QSqlDatabase::d ...