You can define the navigation bar in a separate header.xml layout as follows:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/header_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="fill_parent"
android:layout_height="1px"
android:background="@color/header_border_top" />
<RelativeLayout
android:layout_height="43dp"
android:layout_width="fill_parent"
android:background="@color/header_background">
<LinearLayout
android:id="@+id/header_home_button_layout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_alignParentLeft="true">
<ImageButton
android:id="@+id/header_home_button"
android:src="@drawable/header_btn_home"
android:onClick="onHomeClick" />
</LinearLayout>
<TextView
android:id="@+id/header_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/app_name"
android:textSize="20dp"
android:textStyle="bold"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_alignParentRight="true">
<ImageButton
android:id="@+id/header_back_button"
android:src="@drawable/header_btn_back"
android:onClick="onBackClick"
android:visibility="gone" />
</LinearLayout>
</RelativeLayout>
<ImageView
android:layout_width="fill_parent"
android:layout_height="1px"
android:background="@color/header_border_bottom" />
</LinearLayout>
Then include this heading in the layout of all your actions:
<include
layout="@layout/header" />
And make sure all your classes extend the parent class, which has the onHomeClick and onBackClick methods ...
source
share