How to put back icon in a toolbar inside a fragment that hides the main toolbar?

0

I'm having a problem putting the back icon in a toolbar inside a fragment that is hiding the main toolbar.

I use android studio, and I created a Navigation Drawer Activity, where I work with fragments to open the menu options, and already have a fixed toolbar for all the fragments.

And then a new problem arose. One of the options I tried to put a Scrolling Activity, and I even succeeded, but I was having two toolbars as in the image below:

Pleaseignorethecolors,Ihavenotyetadjustedthelayout.

AndthenIwasabletohidethemaintoolbarusing:

@OverridepublicvoidonResume(){super.onResume();((AppCompatActivity)getActivity()).getSupportActionBar().hide();}@OverridepublicvoidonStop(){super.onStop();((AppCompatActivity)getActivity()).getSupportActionBar().show();}

Andthenitwasalmostperfect,thisway:

ButnowIwantedtoputabackbutton,asinthisexample:

It'seasytoputinwhenyouopenanewActivity,butinthatcaseit'satoolbarinsideafragmentthatishidinganothertoolbar,Icannotimaginehowitdoesit.

ThelayoutfollowsthefragmentIuse.

Layout

<?xmlversion="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="br.com.teste.app.MenuPages.FragmentTerms">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="180dp"
        android:background="@android:color/transparent"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/holo_blue_light"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:toolbarId="@+id/toolbar">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar_custom"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay"
                app:title="Declarações Legais" />

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

<android.support.v4.widget.NestedScrollView 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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:text="@string/terms_text" />

</android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>
    
asked by anonymous 21.02.2018 / 18:46

1 answer

0

I just got it sorted out. perhaps in a gambiarra.

I added an ImageButton with an arrow to go back.

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar_custom"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:title="Declarações Legais">

            <ImageButton
                android:id="@+id/button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@android:color/transparent"
                android:paddingRight="15dp"
                android:src="@drawable/ic_arrow_white" />
        </android.support.v7.widget.Toolbar>

It may not be the best method, and I do not know if it will be cool on all devices, but for now it works. If anyone still knows a better way, please I'd love to hear about other solutions.

    
21.02.2018 / 21:18