代码改变世界

自定义Activity的标题栏

2010-10-25 10:06  stulife  阅读(504)  评论(0编辑  收藏  举报

MyActivity.java

 

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

setContentView(R.layout.main);

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

TextView titleTV = (TextView)findViewById(R.id.title); titleTV.setText(R.string.app_name);

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="fill_parent"     >

<TextView

android:id="@+id/title"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:layout_gravity="center"

android:gravity="center" />

</LinearLayout>