标题栏居中 改变标题栏颜色

一,
1在onCreate()方法中加上这三句话:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 
setContentView(R.layout.main); 
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.title); 
在布局文件中新建一个title.xml文件:
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="center"> 
        <TextView android:id="@+id/textTile" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="title" /> 
</LinearLayout> 
二,
改变标题栏颜色
View bv = this.findViewById(android.R.id.title); 
((TextView) bv).setTextColor(Color.WHITE); 
((View) bv.getParent()).setBackgroundColor(Color.RED);

猜你喜欢

转载自wenlively.iteye.com/blog/1828438