Hasan shaikh
Hasan shaikh

Reputation: 740

how to add a back arrow button of toolbar on to the imageview

In my layout i have an image view at the top without the toolbar. I want to have the back arrow button of toolbar on my imageview, like whatsapp profile view with back arrow on the imageview.

i wanted this resultenter image description here

i got the result by adding this

 getSupportActionBar().setDisplayHomeAsUpEnabled(true);

Upvotes: 0

Views: 3031

Answers (2)

Zahidul Islam
Zahidul Islam

Reputation: 3190

Edit your Toolbar like this.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto" >

    <ImageView
        android:id="@+id/back_button"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:src="@drawable/ic_back_button" />

</android.support.v7.widget.Toolbar>

It will be like this .

enter image description here

Also , You will get the Icon from here .

Upvotes: 1

Saurabh Vardani
Saurabh Vardani

Reputation: 1861

Use the following image and save it to drawable.

enter image description here

and use with the following code

<ImageView
            android:id="@+id/back_arrow"
            android:layout_width="25dp"
            android:layout_height="25dp"
            android:src="@drawable/ic_arrow_back" />

Upvotes: 1

Related Questions