http://blog.csdn.net/mimitracely/article/details/7968944
先在strings.xml 中定义主题
- <style name="customTitlebg" >
- <item name="android:background">@drawable/title_bg</item>
- </style>
- <style name="titlebar" parent="android:Theme">
- <item name="android:windowTitleSize">40dp</item>
- <item name="android:windowTitleBackgroundStyle">@style/customTitlebg</item>
- </style>
- <application
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/titlebar" >
- <activity
- android:name=".MainActivity"
- ...
- <?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/title_home_normal" />
- <TextView android:layout_width="wrap_content"
- android:layout_centerInParent="true"
- android:layout_height="wrap_content"
- android:textColor="#000000"
- android:text="自定义标题栏" />
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentRight="true"
- android:layout_centerVertical="true"
- android:src="@drawable/title_new_normal" />
- </RelativeLayout>
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); //声明使用自定义标题
- setContentView(R.layout.tabhost);
- getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);//自定义布局赋值
- }