- 浏览: 1389017 次
- 性别:
- 来自: 陕西.西安
-
文章分类
最新评论
-
dare_:
经过试验 设置之后反而更慢没有调用ensureCapacity ...
ensureCapacity()方法提高ArrayList的初始化速度 -
wangchao9053:
[flash=200,200][url][img][list] ...
Only the original thread that created a view hierarchy can touch its views的相关 -
cyb504:
考虑将rb文件代码隐藏:我先使用命令jrubyc将所有rb文件 ...
Ruby学习十 JRuby中调用java代码 -
4562xse3460:
大哥,您这个写反了,差点误导我,我觉得看着就不对。百度第一条就 ...
portrait表示纵向,landscape表示横向 -
yin138:
portrait是肖像画,即竖屏,landscape是风景画, ...
portrait表示纵向,landscape表示横向
一个接着一个的activity,写啊写,调啊调,后来,终于发觉,activity的标题栏好难看,好单调啊。咱们为了吸引用户的眼球,得搞点个性化的东西。
自定义标题栏的方法,网上一搜一大堆,我也稍微提一下,oncreate中加上如下代码就行:
- requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
- setContentView(view);
- getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(view); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
这个名为title的layout是这样子的,很简单,就是一个textview,然后有个背景色:
- <? xml version = "1.0" encoding = "utf-8" ?>
- < LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
- android:orientation = "vertical"
- android:layout_width = "fill_parent"
- android:layout_height = "fill_parent"
- android:background = "#66cccccc"
- >
- < TextView
- android:layout_width = "fill_parent"
- android:layout_height = "wrap_content"
- android:text = "hello"
- />
- </ LinearLayout >
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#66cccccc" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="hello" /> </LinearLayout>
好,运行看效果。看到了吧,发现问题了没,标题栏的背景色没有填充满是吧,这可真是杯具哟。padding、margin什么的都用上也不管用,怎么办呢。
看源码!
window初始化,加载标题的地方,咱也不知道在哪里,不过咱能以layout作为切入点。打开源码里面的layout文件夹,找跟标题栏相关的xml
文件。里面有screen_title.xml和screen_custom_title.xml,这就是咱们要找的目标了。
既然是自定义标题,那我们就看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"
好,从这里我们就可以入手改了。
去values下面的themes.xml找到windowTitleBackgroundStyle这一项,这个应该在注释<!-- Window attributes -->的下面。
- < item name = "windowTitleBackgroundStyle" > @android:style/WindowTitleBackground </ item >
<item name="windowTitleBackgroundStyle">@android:style/WindowTitleBackground</item>
然后去styles.xml下找到WindowTitleBackground项,
- < style name = "WindowTitleBackground" >
- < item name = "android:background" > @android:drawable/title_bar </ item >
- </ style >
<style name="WindowTitleBackground"> <item name="android:background">@android:drawable/title_bar</item> </style>
发现是一个drawable,xml的,里面定义了背景图片。ok,我们知道了,这个是定义titlebar的背景色。
然后,去values下面的themes.xml找到windowContentOverlay,也是属于window attributes。
- < item name = "windowContentOverlay" > @android:drawable/title_bar_shadow </ item >
<item name="windowContentOverlay">@android:drawable/title_bar_shadow</item>
发现也是个drawable,ok,我们也知道了,这个是定义contentoverlay的背景的。
其实,通过研究我发现,不能填充满的原因是title_container的背景的原因,我们覆盖一下就行了。
首先,写个themes文件
- < resources >
- < style name = "XTheme" parent = "android:Theme" >
- <!-- Window attributes -->
- < item name = "android:windowTitleStyle" > @style/XWindowTitle </ item >
- < item name = "android:windowTitleBackgroundStyle" > @style/StatusBarBackground </ item >
- < item name = "android:windowContentOverlay" > @null </ item >
- </ style >
- </ resources >
<resources> <style name="XTheme" parent="android:Theme"> <!-- Window attributes --> <item name="android:windowTitleStyle">@style/XWindowTitle</item> <item name="android:windowTitleBackgroundStyle">@style/StatusBarBackground</item> <item name="android:windowContentOverlay">@null</item> </style> </resources>
然后写styles文件
- < resources >
- < style name = "StatusBarBackground" >
- < item name = "android:background" > @drawable/shape </ item >
- </ style >
- < style name = "XWindowTitle" parent = "android:WindowTitle" >
- < item name = "android:shadowColor" > #BB000000 </ item >
- < item name = "android:shadowRadius" > 0 </ item >
- </ style >
- </ resources >
<resources> <style name="StatusBarBackground"> <item name="android:background">@drawable/shape</item> </style> <style name="XWindowTitle" parent="android:WindowTitle"> <item name="android:shadowColor">#BB000000</item> <item name="android:shadowRadius">0</item> </style> </resources>
注意这个XWindowTitle要继承WindowTitle。
最后,在manifext中给自定义的activity申明主题。
- < activity android:name = ".Entry"
- android:label = "@string/app_name"
- android:theme = "@style/XTheme" >
- < intent-filter >
- < action android:name = "android.intent.action.MAIN" />
- < category android:name = "android.intent.category.LAUNCHER" />
- </ intent-filter >
- </ activity >
<activity android:name=".Entry" android:label="@string/app_name" android:theme="@style/XTheme"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
好,我们来看看效果吧:
so cool, isn't it?
当然,你也可以换成别的颜色或者是更炫的图片做背景。
详细实例代码见附件。
http://chroya.iteye.com/blog/760314
发表评论
-
Android检查是否已经连接到网络
2012-05-14 15:40 1290http://blog.csdn.net/kerenigma/ ... -
Android Framework系列之IMF(二)
2011-06-02 10:09 2212InputConnection是IMF里面一个重要的接口,他是 ... -
Android Frameworks系列之IMF(一)
2011-06-02 10:03 1892http://www.pin5i.com/showtopic- ... -
Android线程优先级设置方法
2011-05-28 14:15 3556http://blog.sina.com.cn/s/blog_ ... -
如何连接android数据库
2011-05-27 15:18 2325http://zhidao.baidu.com/questio ... -
ensureCapacity()方法提高ArrayList的初始化速度
2011-05-27 14:33 11588http://www.gznc.edu.cn/yxsz/jjg ... -
java的isAlive 和 join
2011-05-27 13:38 1607join()用于停止当前线程而运行别的线程。 isAli ... -
Linux系统下.ko文件是什么文件?.so文件是什么文件?
2011-05-25 18:55 5615.so 文件是动态链接库文件,相当于 win下的 .dll ... -
使用Geocoder
2011-05-11 10:46 62127.6 使用Geocoder 地理编 ... -
Gallery学习总结--Cache缓存及数据处理流程
2011-05-09 14:21 2209http://hi.baidu.com/%D6%C7%B4%E ... -
关注的网站
2011-04-06 14:37 1080http://blog.sina.com.cn/s/blog_ ... -
gallery3d源码学习总结(二)
2011-04-01 10:40 3565http://www.j2megame.com/htm ... -
gallery3d源码学习总结(一)——绘制流程drawFocusItems
2011-04-01 10:14 4956eoe·Android开发者门户 标题: gallery3d ... -
Android 启动过程详解(学习1)
2011-03-31 09:27 2254Android 启动过程详解 http://blog.csd ... -
Android中的WatchDog (2)
2011-03-31 09:11 1105http://wenku.baidu.com/view/09c ... -
Android平台WindowManager运用
2011-03-30 10:00 1823Android平台WindowManager运用 我们A ... -
JPEG Rotation and EXIF Orientation
2011-03-17 14:26 3936http://blog.csdn.net/daisyhd/ar ... -
Android 的动作、广播、类别等标识大全
2011-03-11 10:19 1336Android 的动作、广播、类别等标识大全 Stri ... -
浅析Android MediaProvider之二
2011-03-08 08:27 2691http://www.poemcode.net/2010/01 ... -
Task和Activity相关
2011-02-28 09:21 1574Task和Activity相关 这段时间在做一个项目,发 ...
相关推荐
在Android或iOS等移动应用开发中,自定义标题栏(customTitleBar)是常见的需求,它可以帮助开发者根据自己的设计风格和功能需求定制应用程序的界面。本文将深入探讨如何实现自定义标题栏,包括如何调整其高度并使其...
----------------------------------- Android 编程基础 1 封面----------------------------------- Android 编程基础 2 开放手机联盟 --Open --Open --Open --Open Handset Handset Handset Handset Alliance ...
这里,`custom_title`是自定义标题栏的布局文件,通常包含应用程序的标题和其他控件,如返回按钮或菜单选项。 #### 总结 蓝牙开发在Android平台上是一个复杂但充满潜力的过程,它允许开发者创建能够连接和控制外部...
在Android开发领域,沉浸式设计(也称为全屏体验或无边界设计)是一种追求极致用户体验的设计模式,它能够提供更为广阔、无干扰的视觉效果,让应用内容充满整个屏幕,从而提升用户的沉浸感。"一个沉浸式设计Demo...
在Android平台上开发一款音乐播放器是一项技术性强且充满挑战的任务。这个"android4.0音乐播放器源码"提供了一个很好的学习平台,帮助开发者深入理解Android应用开发,特别是与音频处理和用户界面设计相关的技术。...
【标题】:“10个插件让你的iPhone比Android更好玩(精编版)” 【描述】:本文介绍了一系列能够提升iPhone用户体验的越狱插件,使得iPhone在功能和个性化方面超越Android设备。 【标签】:iPhone, 越狱, 插件, ...
Toolbar 支持比 ActionBar 更集中的特征,例如导航按钮、品牌的 Logo 图像、标题和子标题、一个或多个自定义视图等。 ```java this.toolbar = (Toolbar) findViewById(R.id.toolbar); this.recyclerview = ...
在实现标题居中这一需求时,我们需要在布局文件中设置`Toolbar`的`android:title`属性或者在代码中调用`setTitle()`方法来设置标题,然后通过调整`Toolbar`的样式或使用自定义的`TextView`实现标题居中对齐。...
在`MainActivity`的`onCreate()`方法中,首先去掉了标题栏,然后设置了布局。关键步骤是获取到`GridView`实例并填充数据。这里使用了`ArrayList, Object>>`来存储每个单元格的数据,每个`HashMap`代表一个单元格的...
java安卓源码特效 9GAG-Android (unofficial) 9GAG 安卓客户端个人版 9GAG安卓客户端,遵从Android Design 作者大三学生一枚,详见about页面,有意...7.ActionBar标题字体自定义 8.Toast自定义 9.支持分享图片+文本,经
为了提供更好的用户体验,当用户将应用添加到主屏幕后,可以自定义标题。这可以通过以下meta标签实现: ```html 标题"> ``` 这里的`content`属性就是显示在主屏幕上的应用名称。这对于提升品牌识别度和用户体验很...