android 制作自定义标题栏

1、在AndroidManifest.xml设置主题

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

2、在layout添加一个文件title_layout.xml

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

    <TextView
        android:id="@+id/textTile"
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:gravity="center|center_horizontal"
        android:layout_gravity="center_horizontal"
        android:text="@string/app_name" />

</RelativeLayout>

3、在其他页面include引用title_layout.xml

        <!-- 顶部title -->
        <include
            android:id="@+id/title_layout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            layout="@layout/title_layout" />
        <!-- 顶部title -->

 

 

 

posted @ 2014-01-18 16:28  传说之美(libill)  阅读(309)  评论(0编辑  收藏  举报