PreferanceActivity和自定义标题栏。

时间:2012-08-06 05:10:54

标签: android

  

可能重复:
  Set custom title bar in PreferenceAcivity

是否可以为preferancActivity添加自定义标题栏?

1 个答案:

答案 0 :(得分:0)

public class Preferences extends PreferenceActivity {  
protected TextView title;
   @Override
   protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);        
    setContentView(R.layout.main_tab);
    title = (TextView) findViewById(R.id.titleTvLeft);

    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);

    this.title.setText("Value");

  }
}

///////在title_bar.xml中///////

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout01"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    fill_parent="" >

    <TextView
        android:id="@+id/titleTvLeft"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="3dp"
        android:textColor="#FFFFFF"
        android:textStyle="bold" >
    </TextView>



</RelativeLayout>