How to change Toolbar Navigation and Overflow Menu icons (appcompat v7)?

To change the navigation icon you can use: Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar); setSupportActionBar(toolbar); toolbar.setNavigationIcon(R.drawable.my_icon); To change the overflow icon you can use the method: toolbar.setOverflowIcon(ContextCompat.getDrawable(this, R.drawable.ic_my_menu); If you would like to change the color of the icons you can use: with a Material Components Theme (with a MaterialToolbar for example): <com.google.android.material.appbar.MaterialToolbar android:theme=”@style/MyThemeOverlay_Toolbar” …> <style … Read more

How can I align Android Toolbar menu/icons to the left like in Google Maps app?

After some struggling and digging in Android Toolbar code I managed to make it work. Basically, the idea is to add a new android.support.v7.widget.ActionMenuView as child of the Toolbar, set its gravity to top|start, and then add the menu to that action menu view in your Activity. Here is the code: my_toolbar.xml <android.support.v7.widget.Toolbar xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” … Read more

How to get Toolbar from fragment?

You need to cast your activity from getActivity() to AppCompatActivity first. Here’s an example: ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(); The reason you have to cast it is because getActivity() returns a FragmentActivity and you need an AppCompatActivity In Kotlin: (activity as AppCompatActivity).supportActionBar?.title = “My Title”

How to hide ToolBar when I scrolling content up?

you have to do many changes in your both layout. first use CoordinatorLayout in activity_main.XML like below(change theme as per your requirement). <?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” android:id=”@+id/main_content” 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/ThemeOverlay.AppCompat.Dark.ActionBar”> <android.support.v7.widget.Toolbar android:id=”@+id/toolbar” android:layout_width=”match_parent” android:layout_height=”?attr/actionBarSize” android:background=”?attr/colorPrimary” android:theme=”@style/ThemeOverlay.AppCompat.Dark.ActionBar” app:layout_scrollFlags=”scroll|enterAlways” app:popupTheme=”@style/ThemeOverlay.AppCompat.Light” /> </android.support.design.widget.AppBarLayout> <include layout=”@layout/content_main” /> </android.support.design.widget.CoordinatorLayout> in content_main.XML use android.support.v4.widget.NestedScrollView instead … Read more

How to use a TabLayout with Toolbar inside CollapsingToolbarLayout?

Here’s the way I managed to do this, I don’t think that’s the best solution though if anyone finds a better way please feel free to post the answer. <android.support.design.widget.CoordinatorLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” android:id=”@+id/main_content” android:layout_width=”match_parent” android:layout_height=”match_parent” android:fitsSystemWindows=”true”> <android.support.v4.view.ViewPager android:id=”@+id/viewpager” android:layout_width=”match_parent” android:layout_height=”match_parent” app:layout_behavior=”@string/appbar_scrolling_view_behavior” /> <android.support.design.widget.AppBarLayout android:id=”@+id/appbar” android:layout_width=”match_parent” android:layout_height=”@dimen/detail_backdrop_height” android:theme=”@style/ThemeOverlay.AppCompat.Dark.ActionBar” android:fitsSystemWindows=”true”> <android.support.design.widget.CollapsingToolbarLayout android:id=”@+id/collapsing_toolbar” android:layout_width=”match_parent” android:layout_height=”206dip” android:background=”@color/primary_dark” app:layout_scrollFlags=”scroll|exitUntilCollapsed” android:fitsSystemWindows=”true” … Read more

Add views below toolbar in CoordinatorLayout

Take the attribute app:layout_behavior=”@string/appbar_scrolling_view_behavior” off the RecyclerView and put it on the FrameLayout that you are trying to show under the Toolbar. I’ve found that one important thing the scrolling view behavior does is to layout the component below the toolbar. Because the FrameLayout has a descendant that will scroll (RecyclerView), the CoordinatorLayout will get … Read more

Cannot catch toolbar home button click event

If you want to know when home is clicked is an AppCompatActivity then you should try it like this: First tell Android you want to use your Toolbar as your ActionBar: setSupportActionBar(toolbar); Then set Home to be displayed via setDisplayShowHomeEnabled like this: getSupportActionBar().setDisplayShowHomeEnabled(true); Finally listen for click events on android.R.id.home like usual: @Override public boolean … Read more

Android – Switch ActionBar Back Button to Navigation Button

If I assume you’re using android.support.v4.widget.DrawerLayout in your layout, then this approach may work for you; I’ve only tested on API 21 but given it’s mostly using the support libraries, it should work (famous last words) on lower or higher targets. import android.support.v7.app.ActionBarDrawerToggle import android.support.v4.widget.DrawerLayout ActionBarDrawerToggle mDrawerToggle; DrawerLayout drawerLayout; private boolean mToolBarNavigationListenerIsRegistered = false; @Override … Read more

Navigation Drawer Below Toolbar

You should move DrawerLayout as top parent and move Toolbar out of DrawerLayout content container. In short this looks like: RelativeLayout —-Toolbar —-DrawerLayout —ContentView —DrawerList <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.android.com/tools” android:id=”@+id/top_parent” android:layout_width=”match_parent” android:layout_height=”match_parent” android:fitsSystemWindows=”true” tools:context=”.MainActivity”> <include android:id=”@+id/toolbar” layout=”@layout/toolbar” /> <android.support.v4.widget.DrawerLayout android:id=”@+id/drawer_layout” android:layout_width=”match_parent” android:layout_height=”match_parent” android:layout_below=”@+id/toolbar”> <FrameLayout android:id=”@+id/content_frame” android:layout_width=”match_parent” android:layout_height=”match_parent” android:background=”@color/background_color” /> <ListView android:id=”@+id/drawer” android:layout_width=”260dp” android:layout_height=”match_parent” android:layout_below=”@+id/toolbar” android:layout_gravity=”start” android:layout_marginTop=”56dp” … Read more