1.自定义Theme。

在res/values/styles.xml中的resources块中添加如下代码:

<style name="StatusBarBackground">    <item name="android:background">#ff888888</item></style><style name="test" parent="android:Theme">     <item name="android:windowTitleSize">50dp</item>    <item name="android:windowTitleBackgroundStyle">@style/StatusBarBackground</item>    </style>

在AndroidMainfest.xml文件中使用该Theme。根据自己的需要在application或者activity块中添加如下语句:

android:theme="@style/test"

2.自定义TitleBar。

在代码中加载界面的地方添加如下代码:

        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);           setContentView(R.layout.activity_main);        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);

注意3条语句的顺序。

其中R.layout.titlebar为自己定义的布局,代码如下:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"     android:background="#333">    <ImageView        android:id="@+id/titleImage"        android:layout_width="50dp"        android:layout_height="50dp"        android:padding="10dp"        android:src="@drawable/ic_drawer">    </ImageView>    <TextView        android:id="@+id/titletext"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:gravity="center_vertical"        android:paddingLeft="6dp"        android:paddingRight="6dp"        android:textColor="#fff" >    </TextView></LinearLayout>

更多相关文章

  1. Delphi XE5 android 黑屏的临时解决办法
  2. Android(安卓)近百个项目的源代码,覆盖Android开发的每个领域
  3. TextView添加Onclick点击无效没反应解决办法
  4. java.lang.ClassCastException: android.app.Application cannot
  5. Android里把Dialog设置为全屏的方法
  6. android 显示特殊符号
  7. android 中调用接口发送短信
  8. 【Android代码片段之四】设置全屏
  9. android 中调用接口发送短信

随机推荐

  1. 为什么代码放到DW里运行,和用记事保存为H
  2. cordova HTML5第一次尝试
  3. jQuery SerialScroll:将类添加到活动项
  4. HTml中面试题 ---&&的作用以及||特点
  5. C++Test的使用说明
  6. HTML H5之ASCII 代码转义字符集实体编号
  7. 我的HTML INPUT无效标记,请帮忙
  8. java 使用htmlunit模拟登录爬取新浪微博
  9. 如何将jQuery输入掩码实现到@ Html.TextB
  10. 是否可以在两行中输出'submit'的值?