您的位置:首页 > 移动开发 > Android开发

Android 自定义标题

2012-08-20 14:16 204 查看
写自定义一个布局XML文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_vertical" >

<TextView
android:id="@+id/titlebar"
android:textColor="#000"
android:paddingRight="5dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>


然后在需要自定义标题的Activity里写入如下代码

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.menu_title);
TextView titleBar = (TextView)findViewById(R.id.titlebar);
titleBar.setText("欢迎你");


requestWindowFeature一般在setContentView之前,setFeatureInt在setContentView之后。

R.layout.menu_title为上面XML布局文件的文件名
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: