I have made a toolbar in main activity where i have set the scroll flags to it but the problrm is that in a fragment hide and show is not working except one fragment it is working in all other fragments and moreover my fab is also not visible but the fab is showing in the preview i do not know where i'm going wrong so please if some one can help me out here
MainActivity.java
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
main activity.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:id="#+id/main_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimary">
<!-- AppBarLayout is a wrapper for a Toolbar in order to apply scrolling effects. -->
<!-- Note that AppBarLayout expects to be the first child nested within a CoordinatorLayout -->
<android.support.design.widget.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar">
<!-- Toolbar is the actual app bar with text and the action items -->
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:titleTextColor="#color/White"
app:layout_scrollFlags="scroll|enterAlways|snap">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottom_navigation"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:animateLayoutChanges="true">
</FrameLayout>
<com.aurelhubert.ahbottomnavigation.AHBottomNavigation
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom" />
</android.support.design.widget.CoordinatorLayout>
and the fragment where it is not working
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.RecyclerView
android:id="#+id/feed_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSize="normal"
android:layout_marginBottom="5dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:src="#drawable/ic_search_black_24dp" />
</RelativeLayout>
Related
I have a screen with some TextViews and EditTexts, and a toolbar.
When I click on an edit text to input some text, the toolbar disappears
How can I make the toolbar be on the screen all the time, even when I introduce the text(or when I scroll, if I introduce a scroll view)
<androidx.constraintlayout.widget.ConstraintLayout 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:id="#+id/createTreasureScreen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".view.fragment.CreateTreasureFragment">
<Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="#dimen/toolbarTreasureHeight"
android:background="#color/Blue"
android:elevation="#dimen/loginToolbarElevation"
android:title="#string/page_title"
android:titleMarginStart="#dimen/toolbarMarginStart"
android:titleTextAppearance="#style/toolbarStyle"
android:titleTextColor="#color/White"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#id/parent"
app:titleEnabled="false" />
</androidx.constraintlayout.widget.ConstraintLayout>
Try using FrameLayout. This will allow you to keep your Toolbar always on top of the other views, and being visible if you add a ScrollView.
<FrameLayout 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">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/createTreasureScreen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".view.fragment.CreateTreasureFragment">
<!--Add your other views here-->
</androidx.constraintlayout.widget.ConstraintLayout>
<Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="#dimen/toolbarTreasureHeight"
android:background="#color/Blue"
android:elevation="#dimen/loginToolbarElevation"
android:title="#string/page_title"
android:titleMarginStart="#dimen/toolbarMarginStart"
android:titleTextAppearance="#style/toolbarStyle"
android:titleTextColor="#color/White"
android:layout_gravity="top"
app:titleEnabled="false" />
</FrameLayout>
I have a requirement to show bottom navigation view, drawer menu in same layout.
Bottom navigation has three tabs each has its own content.The first bottom navigation tab contains a view pager with tablayout that has some conflict with the parent toolbar.
Problem
The child fragment toolbar hides the parent toolbar menu ☰ icon.
Here is the layout I am using.
ParentLayout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="#+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.HomeActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="6dp">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:elevation="0dp"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
app:menu="#menu/navigation" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/nav_header"
app:menu="#menu/menu_drawer" />
</android.support.v4.widget.DrawerLayout>
BottomNavFragment1.xml
<?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:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.telenor.magri.saatdo.activities.TabbedActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/appbar_padding_top"
android:theme="#style/AppTheme.NoActionBar.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/AppTheme.NoActionBar.PopupOverlay" />
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabIndicatorColor="#color/colorPrimaryDark"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
ScreenShot : Child layout having tablayout
ScreenShot : Child layout not having tablayout
But the problem is toolbar menu icon for drawer is not showing up its hiding behind the child toolbar. So any idea what is problem in my layout.
Thanks
You are overriding the Parent Activity toolbar in your Bottom Navigation View- Fragment 1
Change your layout to remove the toolbar..
BottomNavFragment1.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
app:tabGravity="fill"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#3b5998"
android:minHeight="?attr/actionBarSize"
app:tabIndicatorColor="#c8130d"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
</LinearLayout>
EDIT
In your activity layout use layout_below attribute for your FrameLayout
ParentLayout.xml
<FrameLayout
android:id="#+id/container"
android:layout_below = "#+id/appBarLayout" //add this
android:layout_width="match_parent"
android:layout_height="match_parent" />
otherwise it will replace the whole layout including the toolbar in your parent.
I'm using Collapsing toolbar in coordinator layout to achieve the following result. However the problem is when the Collapsing toolbar collapses, the title of the toolbar doesn't show in it proper place for some reason. I couldn't figure out what might be causing this weird issue. How can I fix this?
Support design library: version: 25.1.0
Min SDK: 19
Target SDK: 25
Compile SDK: 25
Following is the code for the fragment shown in the pictures below.
<?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:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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="?attr/colorPrimary"
app:expandedTitleMarginEnd="#dimen/collapsing_toolbar_title_margin_end"
app:expandedTitleMarginStart="#dimen/collapsing_toolbar_title_margin_start"
app:expandedTitleTextAppearance="#style/CollapsedAppBarTextAppearance"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:scaleType="fitXY"
android:src="#drawable/ashiyana_cover"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?android:attr/actionBarSize"
app:layout_collapseMode="pin">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar
android:id="#+id/progressBar"
android:layout_width="#dimen/width_circle_progress_bar"
android:layout_height="#dimen/height_circle_progress_bar"
android:visibility="gone"
app:mlpb_progress_color="#color/colorPrimary"
android:layout_gravity="center"/>
<!-- RECYCLER VIEW FOR DISPLAYING COMICS CARD GRID-->
<android.support.v4.widget.NestedScrollView
android:id="#+id/list_comics"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background_color"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="#+id/button_beAHost"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_top_frag_main_screen"
android:layout_gravity="end"
android:textSize="#dimen/text_size_button_frag_main_screen"
android:text="Be A Host"
tools:text="Be A Host"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="#dimen/padding_main_screen">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/text_size_heading"
android:textColor="#color/title_text_color"
android:text="#string/string_search"
tools:text="Search"/>
<Button
android:id="#+id/button_room"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="#dimen/width_button_search_layout_frag_main_screen"
android:layout_height="#dimen/height_button_search_layout_frag_main_screen"
android:layout_marginTop="#dimen/margin_top_frag_main_screen"
android:paddingStart="#dimen/padding_search_layout_frag_main_screen"
android:paddingLeft="#dimen/padding_search_layout_frag_main_screen"
android:gravity="start|center_vertical"
android:textSize="#dimen/text_size_button_frag_main_screen"
android:text="#string/string_room"
tools:text="Room"/>
<Button
android:id="#+id/button_hostel"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="#dimen/width_button_search_layout_frag_main_screen"
android:layout_height="#dimen/height_button_search_layout_frag_main_screen"
android:layout_marginTop="#dimen/margin_top_frag_main_screen"
android:paddingStart="#dimen/padding_search_layout_frag_main_screen"
android:paddingLeft="#dimen/padding_search_layout_frag_main_screen"
android:gravity="start|center_vertical"
android:textSize="#dimen/text_size_button_frag_main_screen"
android:text="#string/string_hostel"
tools:text="Hostel"/>
<Button
android:id="#+id/button_apartment"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="#dimen/width_button_search_layout_frag_main_screen"
android:layout_height="#dimen/height_button_search_layout_frag_main_screen"
android:layout_marginTop="#dimen/margin_top_frag_main_screen"
android:paddingStart="#dimen/padding_search_layout_frag_main_screen"
android:paddingLeft="#dimen/padding_search_layout_frag_main_screen"
android:gravity="start|center_vertical"
android:textSize="#dimen/text_size_button_frag_main_screen"
android:text="#string/string_apartment"
tools:text="Apartment"/>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Remove the android:fitsSystemWindows="true" and it will work!
The problem might be because in your activity, you forgot to put:
final Toolbar toolbar = findViewById(R.id.toolbar); //or whatever your toolbar id is
setSupportActionBar(toolbar);
I'm new to android development and recently learning about fragments.
I have a recyclerview inside fragment, and I want it to be attached to the toolbar, I tried put app:layout_behavior="#string/appbar_scrolling_view_behavior"
inside the container layout but whenever the toolbar shows the FAB moves down below the navigation bar as you can see here.
activity_main.XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="#+id/main_screen"
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"
tools:context="com.atar.mango.MainActivity">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="#layout/toolbar"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/logo_header"
app:menu="#menu/menu_for_navigation_view"/>
</android.support.v4.widget.DrawerLayout>
home_fragment.XML
<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"
tools:context="com.atar.mango.HomeFragment"
android:background="#color/background">
<TextView
android:id="#+id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/empty"
android:gravity="center"
android:textSize="90sp"
android:textColor="#32000000"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/notes"
app:backgroundTint="#color/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:overScrollMode="never">
</android.support.v7.widget.RecyclerView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/add_note"
app:backgroundTint="#color/options"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginRight="#dimen/fab_margin_right"
android:layout_marginEnd="#dimen/fab_margin_right"
app:layout_anchorGravity="bottom|right|end"
android:layout_marginBottom="16dp"
android:src="#mipmap/add_note"
app:borderWidth="0dp"
android:elevation="6dp"
app:pressedTranslationZ="12dp"
app:fabSize="normal"/>
</android.support.design.widget.CoordinatorLayout>
Thanks.
I think you must specify your layout target,
in this way:
<android.support.design.widget.FloatingActionButton
...
android:layout_gravity="bottom|end|right"
app:layout_anchor="#id/notes"
app:layout_anchorGravity="bottom|right|end"
/>
I am currently redesigning my app to include a navigation drawer for navigating through the app. Currently, each screen is an activity and the way I have designed the home screen, is that it contains a toolbar and another xml file.
<?xml version="1.0" encoding="utf-8"?>
<Toolbar
android:layout_width="match_parent"
android:id="#+id/toolbar"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/AppTheme.PopupOverlay">
<ImageView
android:layout_width="#dimen/_30sdp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_95sdp"
android:src="#drawable/logo"
android:id="#+id/logo"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/sync_green"
android:id="#+id/sync_button"
android:layout_marginStart="#dimen/_75sdp"/>
</Toolbar>
<include layout="#layout/activity_main" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/run"
/>
Now, I have made another XML file for the navigation drawer:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- The main content view where fragments are loaded -->
<FrameLayout
android:id="#+id/flContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="#menu/activity_main_drawer" />
My dilemna is that since my toolbar is in the home.xml fragment, when I switch fragments, I will lose the toolbar. I want to keep the toolbar for all the views in the navigation drawer.
Also, in my java code, the setActionBar(toolbar) is throwing up an error saying cannot resolve method setActionBar.
One simple and straightforwrd solution for integrating NavigationDrawer along with Fragment in an Activity, is to design the activity_main.xml the following way :
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layoutDirection="rtl"
tools:openDrawer="start">
<include
layout="#layout/content_act_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:background="#color/flat_white_light">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
Now, in the content_act_main.xml you can have :
<?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">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="?attr/colorPrimary"
android:theme="#style/ToolbarColoredBackArrow"
app:popupTheme="#style/AppTheme.PopupOverlay" >
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
If you notice, in the conten_act_main.xml, there is a toolbar that will be available to all the content that are shown in the FrameLayout, and you can use this FrameLayout as the container of your Fragments.
You can of course maintain this toolbar, you need ActionBarDrawerToggle to bind the drawerLayout and Toolbar together.
Minimal configuration would be more or less :
ActionBarDrawerToggle actionBarDrawerToggle;
DrawerLayout drawerLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
drawerLayout = (DrawerLayout) findViewById(R.id.navigation_drawer);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
actionBarDrawerToggle = new ActionBarDrawerToggle(this,drawerLayout,toolbar,R.string.app_name,R.string.app_name);
drawerLayout.setDrawerListener(actionBarDrawerToggle);
}
And you put the Toolbar in your base activity layout and other views wrapped in DrawerLayout.
<Android.support.v4.widget.DrawerLayout
xmlns:Android="http://schemas.Android.com/apk/res/Android"
Android:id="#+id/navigation_drawer"
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:fitsSystemWindows="true">
<Android.support.v7.widget.Toolbar
xmlns:Android="http://schemas.Android.com/apk/res/Android"
xmlns:app="http://schemas.Android.com/apk/res-auto"
Android:id="#+id/toolbar"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
></Android.support.v7.widget.Toolbar>
....
....
</Android.support.v4.widget.DrawerLayout>
Try This in your activity
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("");
setSupportActionBar(toolbar);
This is my .xml file
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:paddingBottom="#dimen/design_navigation_separator_vertical_padding"
tools:openDrawer="start">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:orientation="vertical">
<include
android:id="#+id/toolbar"
layout="#layout/apptoolbar" />
<FrameLayout
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/nav_toolbar"
android:clickable="true">
</FrameLayout>
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/appColor"
android:fitsSystemWindows="true"
android:paddingBottom="#dimen/design_navigation_separator_vertical_padding"
app:itemTextAppearance="#style/NavigationDrawerStyle"
app:headerLayout="#layout/nav_header_home"
app:itemBackground="#color/appColor"
app:itemTextColor="#color/drawable_selector_drawer_item"
app:menu="#menu/activity_home_drawer" />
</android.support.v4.widget.DrawerLayout>