Navigation bar common to all activities

I was looking for options for placing a navigation bar common to all activities. Still can't figure out how to do this. The navigation bar should have a title for the screen and a back button. Or maybe two in some actions.
What is the best practice I should follow?

thank

+5
source share
2 answers

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

  <!-- 1px border top -->
  <ImageView
    android:layout_width="fill_parent"
    android:layout_height="1px"
    android:background="@color/header_border_top" />

  <!-- header with text and buttons -->
  <RelativeLayout
    android:layout_height="43dp"
    android:layout_width="fill_parent"
    android:background="@color/header_background">

    <!-- left side -->
    <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">

      <!-- home button -->
      <ImageButton
        android:id="@+id/header_home_button"
        android:src="@drawable/header_btn_home"
        android:onClick="onHomeClick" />

    </LinearLayout>

    <!-- header text -->
    <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"/>

    <!-- right side -->
    <LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="fill_parent"
      android:orientation="horizontal"
      android:layout_alignParentRight="true">

      <!-- back button -->
      <ImageButton
        android:id="@+id/header_back_button"
        android:src="@drawable/header_btn_back"
        android:onClick="onBackClick"
        android:visibility="gone" />

    </LinearLayout>

  </RelativeLayout>

  <!-- 1px border bottom -->
  <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 ...

+1
source

Android Actionbar, , , . , . .

:

enter image description here

+2

All Articles