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>