KiZo
KiZo

Reputation: 543

How to implement back arrow(Up Button) in the vertical center of the Toolbar

When adding back button in Toolbar in landscape mode, back button is not in the vertical center of an toolbar.

Only thing I do is in android manifest:

<activity
        android:name="tack.hardcode.com.tack.MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="landscape">

Here is my toolbar code

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.Toolbar

xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#3F51B5">

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

I also have v21.styles implemented and i have include toolbar in my mainActivity.

What else should I do?!

Upvotes: 1

Views: 671

Answers (2)

Pooja
Pooja

Reputation: 2467

You have set toolbar height to wrap_content causes this problem. Actionbar height is always 56dp in portrait and 48dp in landscape. (For mobile devices)

If you are setting wrap_content as height for toolbar then it took same height for both portrait and landscape. So in portrait mode, up button remains in center while in landscape it goes up and empty space added to the bottom.

So, change toolbar height to android:layout_height="?actionBarSize". By changing this, toolbar takes the same height as actionbar for both in portrait and landscape mode.

Hope it helps to you. And I hope now you are clear.

Upvotes: 2

mehmetunlu
mehmetunlu

Reputation: 239

    Toolbar mToolBar = (Toolbar)findViewById(R.id.toolbar);
    setSupportActionBar (mToolBar);
    ActionBar actionBar = getSupportActionBar ();
    actionBar.setElevation (5);
    actionBar.setDisplayHomeAsUpEnabled(true);

Upvotes: 0

Related Questions