Android 每个Activity界面,都会自动生成一个灰色的标题栏,在编写程序时,可以选择是否有标题栏,或者自定义标题栏,自定义标题栏时,可以在标题栏位置,放置一个布局
系统自带:
可以通过:
this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title);
将标题栏设置成自定义的布局文件:R.layout.custom_title
<?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:gravity="center_vertical"
android:background="@drawable/category_bar"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="这是自定义标题栏"
android:textColor="@android:color/black"
/>
</LinearLayout>
但发现带背景图的自定义标题栏布局无法充满屏幕(横向)
原因是系统默认的样式,预留了左右一小部分空间
解决办法是:
在values资源文件夹下建立my_style.xml文件,内容为:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="android:Theme">
<item name="android:windowTitleBackgroundStyle">@null</item>
</style>
</resources>
自定义样式,继承自系统的主题,设置android:windowTitleBackgroundStyle属性为@null,然后再主配置文件中把Activity的主题设置为自定的MyTheme即可。
<activity android:name=".CustomTitleActivity"
android:theme="@style/MyTheme" android:label="@string/app_name">
效果图:
- 大小: 9.2 KB
- 大小: 9.5 KB
- 大小: 9.4 KB
分享到:
相关推荐
android自定义标题栏源码,自定义view
Android自定义标题栏,需要的童鞋可以下来看看。
xamarin android自定义标题栏,希望能够帮助到大家。。
自定义标题栏 修该 高度 以及 处理没有完全填充bug。
android studio 自定义标题栏,自定义回退按钮事件,自定义右侧显示文字还是图片,自定义右侧点击事件
Android自定义顶部标题栏Android自定义顶部标题栏Android自定义顶部标题栏Android自定义顶部标题栏Android自定义顶部标题栏Android自定义顶部标题栏Android自定义顶部标题栏Android自定义顶部标题栏Android自定义...
NULL 博文链接:https://venus585625.iteye.com/blog/1261421
android 自定义标题栏 CAD如何快速自定义标题栏.docx
Android自定义标题栏(并加入返回按钮)的demo
看IOS上的应用,应用中状态栏的颜色总能与应用标题栏颜色保持一致,用户体验很不错,对于这种效果怎么实现的呢?下面小编给大家分享android自定义状态栏颜色与应用标题栏颜色一致的实现方法,一起看看吧
如题,android自定义标题栏。 http://blog.csdn.net/yanjunhui2011/article/details/64482976 对应资源
Android实现自定义标题栏的高度化自定义
Android复合控件学习之自定义标题栏;学习自定义属性、接口回调等知识点
前段时间android项目中用到一个可以滑动的数量可变的导航栏,在网上也没找到合适的替代品,所以就自定义了个该控件,在此分享一下该控件,给有需要的人。