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

Change Toolbar Menu Item color (non-hidden action)

In your theme file you have to put this : <style name=”AppTheme.ActionBar” parent=”Theme.AppCompat.Light.DarkActionBar”> … <item name=”actionMenuTextColor”>@color/text_color</item> … </style> and apply this theme to your Toolbar view like this : <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/main_toolbar” android:layout_width=”match_parent” android:layout_height=”?attr/actionBarSize” android:background=”?attr/colorPrimary” android:layout_gravity=”top” app:popupTheme=”@style/ThemeOverlay.AppCompat.Light” android:theme=”@style/AppTheme.ActionBar”/> android:theme=”@style/AppTheme.ActionBar” don’t forget this line in your toolbar

“Back button” using getSupportActionbar and appcompat v7 toolbar

Add this method in onCreate(): getSupportActionBar().setDisplayHomeAsUpEnabled(true); Then override the onOptionItemSelected() as below: @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: onBackPressed(); return true; default: return super.onOptionsItemSelected(item); } }

Hide/Show Toolbar programmatically on CoordinatorLayout

If your toolbar is inside an AppBarLayout which is probably inside your CoordinatorLayout then something like this should work. AppBarLayout appBarLayout = (AppBarLayout)findViewById(R.id.appBar); appBarLayout.setExpanded(true, true); Or to collapse it AppBarLayout appBarLayout = (AppBarLayout)findViewById(R.id.appBar); appBarLayout.setExpanded(false, true); Here is the definition setExpanded(boolean expanded, boolean animate) Take note that this method is available from v23 of the support … Read more

How to enable homeAsUp or call setDisplayHomeAsUpEnabled() on standalone toolbar with appcompat v21

@Pedro Oliveira’s solution worked. I could even find the drawable that the AppCompat library uses (and therefore is already included in the apk). What more it’s also mirrored, so it works both for ltr, rtl locales: actionbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha); and this is it alltogether, with the correction from @VictorYakunin public class SettingsActivity extends PreferenceActivity { @Override protected … Read more

How to display and set click event on Back Arrow on Toolbar?

First make one toolbar.xml <?xml version=”1.0″ encoding=”utf-8″?> <android.support.v7.widget.Toolbar xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:local=”http://schemas.android.com/apk/res-auto” android:id=”@+id/toolbar” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:minHeight=”?attr/actionBarSize” android:background=”@color/colorPrimary” local:theme=”@style/ThemeOverlay.AppCompat.Dark.ActionBar” local:popupTheme=”@style/ThemeOverlay.AppCompat.Light” /> then include it in activity_main.xml like this way: <LinearLayout android:id=”@+id/container_toolbar” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:orientation=”vertical”> <include android:id=”@+id/toolbar” layout=”@layout/toolbar” /> </LinearLayout> then in your MainActivity.java file, put this code: mToolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(mToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setTitle(“MyTitle”); To add listener … Read more

android lollipop toolbar: how to hide/show the toolbar while scrolling?

As far as I know there is nothing build in that does this for you. However you could have a look at the Google IO sourcecode, especially the BaseActivity. Search for “auto hide” or look at onMainContentScrolled In order to hide the Toolbar your can just do something like this: toolbar.animate().translationY(-toolbar.getBottom()).setInterpolator(new AccelerateInterpolator()).start(); If you want … Read more