首先写下怎么自定义标题栏:
1、title.xml创建一个layout的xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/navigationstyle">//注意这个地方,我在这个地方给标题栏设置个了背景图片,发现自定义后的标题栏填充不满;
<TextView
android:id="@+id/Titletext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textSize="21sp"
android:layout_marginTop="3dp"
android:textColor="#ffffffff"
android:textStyle="bold"
/>
<Button
android:id="@+id/TitleBackBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/sort"
android:gravity="center"
android:layout_marginTop="9dp"
android:layout_alignParentRight="true"/>
</RelativeLayout>
2、在Activity中进行修改
public class MainPage extends Activity{
private TextView title_text;//title显示的文字
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.CustomTheme);//注意顺序;注意这里的style
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);//title用
setContentView(R.layout.cs);//mainpage
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);//title用
//======================================================
title_text=(TextView)findViewById(R.id.Titletext);//设置title
title_text.setText("xxx");
}
3、在styles.xml中加上步骤2中的样式
<!--title -->
<style name="CustomTheme" parent="android:Theme.Light">
<item name="android:windowTitleSize">40dip</item>
<item name="android:windowTitleBackgroundStyle">@drawable/navigationstyle</item>//注意这里,如果不写这个就会填充不满,我测试后得到的结果
</style>
总结下,俩个地方都要加上这个背景图片。。。。及能填充满了