这个问题困扰了我很久,惊喜地发现官方给的界面风格里竟然有没有标题栏的。DeviceDefault下有好几种NoActionBar的风格,在value文件夹下建立styles.xml文件,选择你需要的NoActionBar风格即可。
<?xml version="1.0" encoding="utf-8"?> <resources xmlns:tools="http://schemas.android.com/tools"> <style name="AppBaseTheme" parent="android:Theme.DeviceDefault.Light.Dialog.NoActionBar" tools:targetApi="ice_cream_sandwich" /> </resources>
隐藏掉所有界面的标题栏后就可以设计自己的标题栏了,在layout文件夹下建立layout.xml文件在所需位置设计自己的标题栏,然后在其他xml文件内留出对应空间调用layout.xml即可。
一个做的很菜的例子
两边是两个按钮图片,分别是返回和菜单,中间留出TextView可以不同页面显示不同内容。
<?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="40dp" android:orientation="horizontal" android:background="@drawable/beijing"> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0" android:layout_gravity="center|left" android:background="@drawable/ic_left" /> <TextView android:id="@+id/textView1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:layout_gravity="center" android:gravity="center" android:text="" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0" android:layout_gravity="right|center" android:background="@drawable/caidan" /> </LinearLayout>
设计的标题栏共占40dp高度,在所需的xml内顶端开个40dp高度的LinearLayout再调用layout.xml
<LinearLayout android:id="@+id/LinearLayout00" android:layout_width="match_parent" android:layout_height="40dp"> <include layout="@layout/layout"/> </LinearLayout>