原装的Android标题栏配色比较单调,就是黑色的一坨,现在假设你的软件需要独自添加标题栏,这样不仅美观而且可以将进度条等加进去,如何实现:

方法一:在你的那张Activity中onCreate方法中加上下面代码:

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);   setContentView(R.layout.main);  //软件activity的布局 getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar); //titlebar为自己标题栏的布局

方法二:

因此先定义一个style,若修改背景请修改android:windowTitleBackgroundStyle
若修改标题栏高度,请修改android:windowTitleSize

例子:

<?xml version="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="CustomWindowTitleBackground">     <item name="android:background">#565656item> style> <style name="test" parent="android:Theme">    <item name="android:windowTitleSize">50dpitem>    <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground style> resources>

在程序的android_manifest.xml中对应activity中添加属性android:theme = “@style/test” 就可以了

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"   package="com.guardian"   android:versionCode="1"   android:versionName="1.0">   <application android:icon="@drawable/icon" android:label="@string/app_name" >     <activity android:name=".Test"         android:label="@string/app_name"         android:theme = "@style/test"  //就在这里          >       <intent-filter>         <action android:name="android.intent.action.MAIN" />         <category android:name="android.intent.category.LAUNCHER" />       intent-filter>     activity>   application>   <uses-sdk android:minSdkVersion="4" /> manifest>

之后借助于设置自定义的标题栏xml文件,就可以自定义标题栏布局了

更多相关文章

  1. Android——Listview不用notifydatasetchanged更新数据的方法
  2. Android中两种使用Animation的方法
  3. 详解Android aidl的使用方法
  4. Genymotion Android模拟器下载和找不到模拟器解决方法
  5. Android app闪退后fragment重叠bug解决方法
  6. 安卓课程六 android常用布局属性的介绍
  7. Android 约束布局(ConstraintLayout)的使用
  8. Android高手进阶教程(六)之----Android 中MenuInflater的使用(布
  9. zz:Android 测试工具Monkey & Monkeyrunner 使用方法

随机推荐

  1. Unity调用Android保存图片到相册
  2. Android(安卓)3.0 硬件加速
  3. Android图片压缩
  4. android IntentService的深入理解
  5. Android中Spinner的用法
  6. android ndk 开发
  7. Android(安卓)studio SDK6.0 不支持HttpC
  8. Android(安卓)Signing your Applications
  9. 模拟android访问服务器
  10. Android:EditText插入图片实现图文混排