1、首先导入ActionBarActivity包,然后将MainActivity继承Activity而不是ActionBarActivity(注意这里只改变的了主界面的标题)
import android.support.v7.app.ActionBarActivity;
public class MainActivity extends Activity //不然会出现异常
2、在MainActivity中添加以下语句
this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);//<span style="font-family: Arial, Helvetica, sans-serif;">R.layout.main为你的布局文件</span>
this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.title);//<span style="font-family: Arial, Helvetica, sans-serif;">R.layout.title为你删除标题后的布局文件</span>
3、在layout中建立title.xml布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tbartxt"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/app_name"
android:textSize="19dp"
android:textColor="#ffffff"
android:gravity="center">
</TextView>
</LinearLayout>
4、修改标题属性,在values文件夹中建立style.xml文件,修改标题栏背景以及高度,默认高度为26dip,可自行修改
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#09adeb</item>
</style>
<style name="title_style" parent="android:Theme">
<item name="android:windowTitleSize">26dip</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
5、在你所要修改标题的文件中添加主题
<activity
android:name=".MainActivity"
android:label="@string/app_name"
<strong>android:theme="@style/title_style"</strong>
>
6、注意以上只是更改了部分activity的标题,只是局部修改,在修改了标题栏后,整个activity的布局会发生改变,所以必须修改相应的布局管理文件.xml文件