Toolbar options menu background color

To change the toolbar options menu color, add this to your toolbar element app:popupTheme=”@style/MyDarkToolbarStyle” Then in your styles.xml define the popup menu style <style name=”MyDarkToolbarStyle” parent=”ThemeOverlay.AppCompat.Light”> <item name=”android:colorBackground”>@color/mtrl_white_100</item> <item name=”android:textColor”>@color/mtrl_light_blue_900</item> </style> Note that you need to use colorBackground not background. The latter would be applied to everything (the menu itself and each menu item), the … Read more

setSupportActionBar toolbar cannot be applied to (android.widget.Toolbar) error

In your Activity.java import android.support.v7.widget.Toolbar instead of android.widget.Toolbar: import android.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.support.v7.widget.Toolbar; public class rutaActivity extends AppCompactActivity { private Toolbar toolbar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ruta); getSupportActionBar().hide();//Ocultar ActivityBar anterior toolbar = (Toolbar) findViewById(R.id.app_bar); setSupportActionBar(toolbar); //NO PROBLEM !!!! Update: If you are using androidx, replace … Read more

Don’t collapse Toolbar when RecyclerView fits the screen

Final Solution (thanks Michał Z.) Methods to turn off/on Toolbar scrolling: public void turnOffToolbarScrolling() { Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar); AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appbar_layout); //turn off scrolling AppBarLayout.LayoutParams toolbarLayoutParams = (AppBarLayout.LayoutParams) mToolbar.getLayoutParams(); toolbarLayoutParams.setScrollFlags(0); mToolbar.setLayoutParams(toolbarLayoutParams); CoordinatorLayout.LayoutParams appBarLayoutParams = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams(); appBarLayoutParams.setBehavior(null); appBarLayout.setLayoutParams(appBarLayoutParams); } public void turnOnToolbarScrolling() { Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar); AppBarLayout appBarLayout = … Read more

How to set Toolbar text and back arrow color

Chances are you are extending from the wrong parent. If not, you can try adding the style to the toolbar layout directly, if you want to override the theme’s settings. In your toolbar layout: <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=”?attr/actionBarSize” android:minHeight=”?attr/actionBarSize” app:theme=”@style/ToolBarStyle” app:popupTheme=”@style/ToolBarPopupStyle” android:background=”@color/actionbar_color” /> In your styles: <!– ToolBar –> <style name=”ToolBarStyle” parent=”Theme.AppCompat”> <item … 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 change Toolbar home icon color

I solved it by editing styles.xml: <style name=”ToolbarColoredBackArrow” parent=”AppTheme”> <item name=”android:textColorSecondary”>INSERT_COLOR_HERE</item> </style> …then referencing the style in the Toolbar definition in the activity: <LinearLayout android:id=”@+id/main_parent_view” android:layout_width=”match_parent” android:layout_height=”match_parent” android:orientation=”vertical”> <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” app:theme=”@style/ToolbarColoredBackArrow” app:popupTheme=”@style/AppTheme” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:minHeight=”?attr/actionBarSize” android:background=”?attr/colorPrimary”/>

MenuItem tinting on AppCompat Toolbar

After the new Support library v22.1, you can use something similar to this: @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_home, menu); Drawable drawable = menu.findItem(R.id.action_clear).getIcon(); drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(drawable, ContextCompat.getColor(this,R.color.textColorPrimary)); menu.findItem(R.id.action_clear).setIcon(drawable); return true; }

Creating a SearchView that looks like the material design guidelines

It is actually quite easy to do this, if you are using android.support.v7 library. Step – 1 Declare a menu item <item android:id=”@+id/action_search” android:title=”Search” android:icon=”@drawable/abc_ic_search_api_mtrl_alpha” app:showAsAction=”ifRoom|collapseActionView” app:actionViewClass=”android.support.v7.widget.SearchView” /> Step – 2 Extend AppCompatActivity and in the onCreateOptionsMenu setup the SearchView. import android.support.v7.widget.SearchView; … public class YourActivity extends AppCompatActivity { … @Override public boolean onCreateOptionsMenu(Menu menu) … Read more

In android app Toolbar.setTitle method has no effect – application name is shown as title

Found the solution: Instead of: mActionBarToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar); mActionBarToolbar.setTitle(“My title”); setSupportActionBar(mActionBarToolbar); I used: mActionBarToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar); setSupportActionBar(mActionBarToolbar); getSupportActionBar().setTitle(“My title”); And it works.