-4

I am very new in Android. I want to put a header on the top of the activity, similar to UINavigationBar in iOS. I need to put an icon on the left side of the header and a title (either text or an image with logo & title). Please find the image link to know how I want the header.

https://www.dropbox.com/s/onsc3klzc0bafia/Screen%20Shot%202016-12-08%20at%201.00.13%20PM.png?dl=0

Ankita Shah
  • 1,866
  • 16
  • 31
sree_iphonedev
  • 3,514
  • 6
  • 31
  • 50
  • Visit this link: http://stackoverflow.com/questions/40960334/action-bar-with-back-arrow/40960576#40960576 – Satan Pandeya Dec 08 '16 at 08:03
  • You can use `ToolBar` as a header and if you want to use `Drawable` icon. In Android Studio: Go `File/New/Vector Asset/Icon` . Click on icon and select the require one and use. Use require icon instead of back icon. – Satan Pandeya Dec 08 '16 at 08:06

1 Answers1

3

User this in your 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="match_parent"
    android:orientation="vertical">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/colorPrimary"
    android:elevation="4dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

<FrameLayout
    android:id="@+id/frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</LinearLayout>

and then in the activity onCreate(); add this

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_toolbar);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("YOUR_TITLE");
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

This line will add the arrow at the left corner of the toolbar

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Tabish Hussain
  • 852
  • 5
  • 13