Search code examples
androidandroid-toolbarandroid-collapsingtoolbarlayout

why back button not showing center in toolbar?


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


Solution

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