This question already has answers here:
NavigationView OnNavigationItemSelectedListener not being called
(3 answers)
Navigation Drawer closes on click
(1 answer)
Android studio 3.5 refactor issue
(9 answers)
Closed 3 years ago.
I have updated the Android Studio to version 3.5 from August 9 2019. I have tried to get familiar with new idea for navigation drawer using Navigation Component. I created the new project and chose the Navigation Drawer Activity at start. After that, I have tried to run the app to see if everything works fine but the drawer menu doesn't work. The drawer gets open but when I click on any available items it just close the drawer not opening proper fragment. I have also tried to set different fragment as a Start Destination and it works fine, the correct fragment gets open at start correctly however the drawer menu still doesn't work.
What am I missing? How can I make it work?
Code comes straight from the fresh new Navigation Drawer Activity:
activity_main:
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.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"
tools:openDrawer="start">
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.drawerlayout.widget.DrawerLayout>
app_bar_main:
<androidx.coordinatorlayout.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=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.floatingactionbutton.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"
app:srcCompat="#android:drawable/ic_dialog_email" />
<include layout="#layout/content_main" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
content_main:
<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:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/app_bar_main">
<fragment
android:id="#+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="#navigation/mobile_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
activity_main_drawer:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_home"
android:icon="#drawable/ic_menu_camera"
android:title="#string/menu_home" />
<item
android:id="#+id/nav_gallery"
android:icon="#drawable/ic_menu_gallery"
android:title="#string/menu_gallery" />
<item
android:id="#+id/nav_slideshow"
android:icon="#drawable/ic_menu_slideshow"
android:title="#string/menu_slideshow" />
<item
android:id="#+id/nav_tools"
android:icon="#drawable/ic_menu_manage"
android:title="#string/menu_tools" />
</group>
<item android:title="Communicate">
<menu>
<item
android:id="#+id/nav_share"
android:icon="#drawable/ic_menu_share"
android:title="#string/menu_share" />
<item
android:id="#+id/nav_send"
android:icon="#drawable/ic_menu_send"
android:title="#string/menu_send" />
</menu>
</item>
</menu>
mobile_navigation:
<navigation 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/mobile_navigation"
app:startDestination="#+id/nav_home">
<fragment
android:id="#+id/nav_home"
android:name="com.broadenup.test.ui.home.HomeFragment"
android:label="#string/menu_home"
tools:layout="#layout/fragment_home" />
<fragment
android:id="#+id/nav_gallery"
android:name="com.broadenup.test.ui.gallery.GalleryFragment"
android:label="#string/menu_gallery"
tools:layout="#layout/fragment_gallery" />
<fragment
android:id="#+id/nav_slideshow"
android:name="com.broadenup.test.ui.slideshow.SlideshowFragment"
android:label="#string/menu_slideshow"
tools:layout="#layout/fragment_slideshow" />
<fragment
android:id="#+id/nav_tools"
android:name="com.broadenup.test.ui.tools.ToolsFragment"
android:label="#string/menu_tools"
tools:layout="#layout/fragment_tools" />
<fragment
android:id="#+id/nav_share"
android:name="com.broadenup.test.ui.share.ShareFragment"
android:label="#string/menu_share"
tools:layout="#layout/fragment_share" />
<fragment
android:id="#+id/nav_send"
android:name="com.broadenup.test.ui.send.SendFragment"
android:label="#string/menu_send"
tools:layout="#layout/fragment_send" />
</navigation>
Related
I'm using Android support design widget BottomNavigationView for making my bottom navigation items. It doesn't show the icons, but it shows text and is working fine. I am using the support library version com.google.android.material:material:1.4.0 and my XML code for bottomnavigationView is:
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
tools:context=".MainActivity">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#drawable/gradient_bg"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_30sdp">
<ImageView
android:layout_width="#dimen/_55sdp"
android:layout_height="#dimen/_35sdp"
android:src="#drawable/logo1" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_54sdp"
android:gravity="center"
android:text=""
android:textColor="#color/white"
android:textSize="#dimen/_12sdp" />
</androidx.appcompat.widget.Toolbar>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/layout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toolbar" />
<LinearLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="#dimen/_45sdp"
android:layout_weight="0.90"
android:background="#color/app_col1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
android:gravity="center"
android:orientation="vertical">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_nav_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/app_col1"
app:itemIconTint="#color/white"
app:labelVisibilityMode="labeled"
android:layout_gravity="center"
android:theme="#style/Theme.App"
app:itemTextColor="#drawable/tab_color"
app:menu="#menu/bottom_navigation_menu"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
My menu XML code is below
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/page_1"
android:enabled="true"
android:iconTint="#drawable/ic_baseline_home_24"
app:showAsAction="ifRoom"
android:title="Home"/>
<item
android:id="#+id/page_2"
android:iconTint="#drawable/ic_baseline_home_24"
app:showAsAction="withText"
android:title="Category"/>
<item
android:id="#+id/page_3"
app:showAsAction="ifRoom"
android:iconTint="#drawable/user"
android:title="Profile"/>
</menu>
How can I solve this issue?
In your activity layout add the following code.
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/btmMenu"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
app:itemIconSize="#dimen/bottom_navigation_icon_size"
app:labelVisibilityMode="labeled"
android:background="#color/white_color"
app:menu="#menu/menu"
app:elevation="0dp"></com.google.android.material.bottomnavigation.BottomNavigationView>
Create a menu.xml file and add the below code.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/Home"
android:title="Home"
android:icon="#drawable/home_selector"/>
<item
android:id="#+id/Statistics"
android:title="Statistics"
android:icon="#drawable/statitics_selector"/>
<item
android:id="#+id/Analytics"
android:title="Analytics"
android:icon="#drawable/analytics_selector"/>
<item
android:id="#+id/Profile"
android:title="Profile"
android:icon="#drawable/profile_selector"/>
</menu>
I've been trying to get a BottonNavigationView working. It just keeps sticking to the top of the layout and it's driving me nuts.
I've looked at Material Design Documentation for BottomNavigationView and it seems really simple, but I can't get it to work, https://material.io/develop/android/components/bottom-navigation/. I even tried making a completely clean project where I tried it and the same thing happened.
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity"
android:id="#+id/mainLayout">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
app:menu="#menu/bottom_bar_menu" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/content"
android:enabled="true"
android:icon="#drawable/ic_menu_black_24dp"
android:title="Content"/>
<item
android:id="#+id/document"
android:enabled="true"
android:icon="#drawable/ic_picture_as_pdf_black_24dp"
android:title="Document"/>
<item
android:id="#+id/search"
android:enabled="true"
android:icon="#drawable/ic_search_black_24dp"
android:title="Search"/>
</menu>
Screenshot
Any ideas?
The gravity of your bottom navigation is set to start android:layout_gravity="start" changing it to android:layout_gravity="bottom" should work for you.
I would like to recommend to use ConstraintLayout and set constraints in Designer tool. Will be easier if you are new in android world.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/bottom_bar_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
I am trying to use Bottom Navigation Activity. I use the default 3 menu items with their fragments.
My problem is, I am seeing a gap between the ActionBar and the fragment. In the activity_main, I set the height to match_parent.
I tried to see if anyone else has this problem but could not come across.
In the activity_main.xml file, I have the code that comes with a creation of a new activity:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="#menu/bottom_nav_menu" />
<fragment
android:id="#+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="#id/nav_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
app:navGraph="#navigation/mobile_navigation"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
bottom_nav_menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/navigation_home"
android:icon="#drawable/ic_home_black_24dp"
android:title="#string/title_home" />
<item
android:id="#+id/navigation_dashboard"
android:icon="#drawable/ic_dashboard_black_24dp"
android:title="#string/title_dashboard" />
<item
android:id="#+id/navigation_notifications"
android:icon="#drawable/ic_notifications_black_24dp"
android:title="#string/title_notifications" />
</menu>
mobile_navigation.xml
<navigation 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/mobile_navigation"
app:startDestination="#+id/navigation_home">
<fragment
android:id="#+id/navigation_home"
android:name="com.zakuto.myapplication.ui.home.HomeFragment"
android:label="#string/title_home"
tools:layout="#layout/fragment_home" />
<fragment
android:id="#+id/navigation_dashboard"
android:name="com.zakuto.myapplication.ui.dashboard.DashboardFragment"
android:label="#string/title_dashboard"
tools:layout="#layout/fragment_dashboard" />
<fragment
android:id="#+id/navigation_notifications"
android:name="com.zakuto.myapplication.ui.notifications.NotificationsFragment"
android:label="#string/title_notifications"
tools:layout="#layout/fragment_notifications" />
</navigation>
Below a screenshot of the screen.
Your layout has a padding-top. Remove this line
android:paddingTop="?attr/actionBarSize"
I want to make menu item in different color when it is clicked and also persist the color as it was selected from the list. currently it is not showing the green color when an item is selected
shape_drawer_menu_item.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/drawer_menu" android:state_pressed="false" />
<item android:drawable="#color/drawer_menu_selected_item" android:state_checked="true"/>
<item android:drawable="#color/drawer_menu_selected_item" android:state_activated="true"/>
<item android:drawable="#color/drawer_menu_selected_item" android:state_pressed="true"/>
<item android:drawable="#color/drawer_menu_selected_item" android:state_active="true" />
</selector>
menu_drawer.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_featured"
android:icon="#drawable/ic_nav_featured"
android:title="#string/title_nav_featured"
android:checkable="true"
android:checked="true"/>
<item
android:id="#+id/nav_tour"
android:icon="#drawable/ic_nav_tour"
android:title="#string/title_nav_tour" />
</group>
</menu>
activity_main.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_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#1C3553">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways">
<include layout="#layout/toolbar" />
</FrameLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="#+id/frame_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/appbar"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/spacing_large"
android:clickable="true"
android:src="#drawable/ic_search"
android:tint="#android:color/white"
app:layout_anchor="#id/frame_content"
app:layout_anchorGravity="end|bottom" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="#dimen/drawer_menu_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:itemTextColor="#android:color/white"
app:itemBackground="#drawable/shape_drawer_menu_item"
android:fitsSystemWindows="false"
android:scrollbars="none"
android:background="#2F3847"
app:headerLayout="#layout/nav_header"
app:itemIconTint="#android:color/white"
app:menu="#menu/menu_drawer"
/>
</android.support.v4.widget.DrawerLayout>
ActivityMain.java
OnCreate() =>
navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(MenuItem item) {
actionBar.setTitle(item.getTitle().toString());
//item.setChecked(true);
navigationView.setCheckedItem(item.getItemId());
boolean s=item.isEnabled();
return onItemSelected(item.getItemId());
}
});
You need to remove group checkable behaviour attribute and put only put checkable = true in your item, it will works. Best of luck!!
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group>
<item
android:id="#+id/nav_featured"
android:icon="#drawable/ic_nav_featured"
android:title="#string/title_nav_featured"
android:checkable="true"/>
<item
android:id="#+id/nav_tour"
android:icon="#drawable/ic_nav_tour"
android:title="#string/title_nav_tour"
android:checkable="true" />
</group>
</menu>
I am trying to recreate this menu setup in Android:
But I can only get this:
I can't seem to get rid of the WebBrowser text in the toolbar without the app crashing. Additionally I can't space out the icons.
There is a small Progress bar between the forward and back buttons.
Any help?
Here is my menu_main.xml
<menu 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"
tools:context="net.txisystems.txiwebbrowser.MainActivity">
<item
android:id="#+id/action_home"
android:icon="#drawable/ic_house"
android:menuCategory="secondary"
android:orderInCategory="1"
android:title="#string/action_refresh"
app:showAsAction="always" />
<item
android:id="#+id/action_back"
android:icon="#drawable/ic_back"
android:menuCategory="secondary"
android:orderInCategory="2"
android:title="#string/action_refresh"
app:showAsAction="always" />
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<item
android:id="#+id/action_forward"
android:icon="#drawable/ic_forward"
android:menuCategory="secondary"
android:orderInCategory="3"
android:title="#string/action_refresh"
app:showAsAction="always" />
<item
android:id="#+id/action_refresh"
android:icon="#drawable/ic_refresh"
android:menuCategory="secondary"
android:orderInCategory="4"
android:title="#string/action_refresh"
app:showAsAction="always" />
</menu>
Placing the progress bar in my activity_main.xml under the toolbar I get this:
Here is the activity_main.xml code:
<?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="net.txisystems.webbrowser.MainActivity">
<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="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
<ProgressBar
android:indeterminate="true"
android:visibility="visible"
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleSmall"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
To remove title use in your activity/fragment
toolbar.setTitle(null)
You cannot put progressbar into menu.xml file
Use RelativeLayout inside Toolbar and put all views you need there like this:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:elevation="4dp"
android:layout_width="match_parent"
app:layout_scrollFlags="scroll|enterAlways"
android:layout_height="?attr/actionBarSize"
android:background="#drawable/gradient"
app:popupTheme="#style/AppTheme.PopupOverlay">
<ProgressBar
android:indeterminate="true"
android:visibility="invisible"
android:id="#+id/toolbar_progress_bar"
android:layout_width="28dp"
android:layout_marginRight="16dp"
android:layout_height="28dp"
android:indeterminateTint="#fff"
android:indeterminateTintMode="src_in"
android:layout_gravity="right"
/>