-1

i am using collapsing toolbar and i am trying to show back button it's it's not showing in center_vertical in toolbar.

output that i am getting

Does anyone know why i am getting this output?

Style

<style name="AppThemeNoActionBarNotch" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">#1A000000</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:fitsSystemWindows">true</item>
</style>

I am using this style because i want to show image preview also in status bar.

layout file

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activity.PerformarEventActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/_200sdp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<android.support.design.widget.CollapsingToolbarLayout
    android:id="@+id/collapsing_toolbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    app:contentScrim="@color/colorPrimary"
    app:expandedTitleMarginEnd="@dimen/_64sdp"
    app:expandedTitleMarginStart="@dimen/_48sdp"
    app:expandedTitleTextAppearance="@style/TextAppearance.AppCompat.Headline"
    app:layout_scrollFlags="scroll|exitUntilCollapsed">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/imgperformarbg"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:scaleType="fitXY"
            android:background="@drawable/publiek"
            app:layout_collapseMode="parallax" />

        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="bottom"
            android:background="@drawable/gradient"/>
    </RelativeLayout>

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:layout_collapseMode="pin"
        app:titleTextColor="@color/white" />

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

</android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main_sub" />  //RECYCLERVIEW LAYOUT


</android.support.design.widget.CoordinatorLayout>

this is my code

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setTitle(performer_name);
    toolbar.setNavigationIcon(R.drawable.ic_arrow_back_black_24dp);

Any help would be highly appreciated

MrEngineer13
  • 38,642
  • 13
  • 74
  • 93
Keyur Patel
  • 172
  • 1
  • 2
  • 12

3 Answers3

3

Toolbar supports a more focused feature set than ActionBar. From start to end, a toolbar may contain a combination of the following optional elements: A navigation button. This may be an Up arrow, navigation menu toggle, close, collapse, done or another glyph of the app's choosing. This button should always be used to access other navigational destinations within the container of the Toolbar and its signified content or otherwise leave the current context signified by the Toolbar. The navigation button is vertically aligned within the Toolbar's minimum height, if set.

So if you set minHeight attribute the same as your toolbar height (layout_height ), the back arrow will be centered vertically.

More clarification in developer.android.com

SIDHARTH P U
  • 282
  • 1
  • 14
0

after removing fitsSystemWindows="true" from the style and putting fitsSystemWindows="true" to all of the tags, it worked.

Keyur Patel
  • 172
  • 1
  • 2
  • 12
0

set minHeight attribute the same as your toolbar height (layout_height ), the back arrow will be centered vertically.

Tushar Ahmed
  • 101
  • 6