Android程序中默认标题栏是灰色背景,内容是工程名字,类似下图:
修改了标题栏布局,效果如下:
说一下具体步骤。首先,修改标题栏的宽度和背景,在strings.xml中添加:
<style name="CustomWindowTitleBackground">
<item name="android:background">@drawable/title_bg</item>
</style>
<style name="test" parent="android:Theme">
<item name="android:windowTitleSize">40dp</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
然后修改AndroidMainfest.xml文件:
<activity android:name=".MainActivity"
android:theme="@style/test">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
红色部分为加载Activity的theme。
接着修改MainActivity:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); //声明使用自定义标题
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);//自定义布局赋值
}
注意红色部分标记的3行代码,顺序不能颠倒。
最后在layout文件夹中添加title.xml文件,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:layout_width="wrap_content"
android:layout_centerVertical=’true’
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher_email" />
<TextView android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:layout_height="wrap_content"
android:text="自定义标题栏" />
</RelativeLayout>
重新部署程序,效果如上图。源码连接:http://bigcateasymorse.googlecode.com/svn/trunk/androidcustomtitle/转自:http://bigcat.easymorse.com/?p=840
分享到:
相关推荐
android自定义标题栏源码,自定义view
xamarin android自定义标题栏,希望能够帮助到大家。。
android 自定义标题栏 CAD如何快速自定义标题栏.docx
Android自定义标题栏(并加入返回按钮)的demo
NULL 博文链接:https://venus585625.iteye.com/blog/1261421
自定义标题栏 修该 高度 以及 处理没有完全填充bug。
如题,android自定义标题栏。 http://blog.csdn.net/yanjunhui2011/article/details/64482976 对应资源
Android自定义顶部标题栏Android自定义顶部标题栏Android自定义顶部标题栏Android自定义顶部标题栏Android自定义顶部标题栏Android自定义顶部标题栏Android自定义顶部标题栏Android自定义顶部标题栏Android自定义...
android studio 自定义标题栏,自定义回退按钮事件,自定义右侧显示文字还是图片,自定义右侧点击事件
看IOS上的应用,应用中状态栏的颜色总能与应用标题栏颜色保持一致,用户体验很不错,对于这种效果怎么实现的呢?下面小编给大家分享android自定义状态栏颜色与应用标题栏颜色一致的实现方法,一起看看吧
NULL 博文链接:https://lovezhou.iteye.com/blog/861589
Android实现自定义标题栏的高度化自定义
Android复合控件学习之自定义标题栏;学习自定义属性、接口回调等知识点
主要介绍了 Android 自定义标题栏的实例详解的相关资料,希望通过本文能帮助到大家,让大家实现这样类似的功能,需要的朋友可以参考下