How to center toolbar back button?

From the developer.android.com : Toolbar supports a more focused feature set than ActionBar. From start to end, a toolbar may contain a combination of the following optional elements: A navigation button. This may be an Up arrow, navigation menu toggle, close, collapse, done or another glyph of the app’s choosing. This button should always be … Read more

How to display menu item with icon and text in AppCompatActivity

@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. // getMenuInflater().inflate(R.menu.menu_patient_home_screen, menu); menu.add(0, 1, 1, menuIconWithText(getResources().getDrawable(R.mipmap.user_2), getResources().getString(R.string.action_profile))); menu.add(0, 2, 2, menuIconWithText(getResources().getDrawable(R.mipmap.add_user), getResources().getString(R.string.action_add_user))); menu.add(0, 3, 3, menuIconWithText(getResources().getDrawable(R.mipmap.switch_profile), getResources().getString(R.string.action_switch_profile))); menu.add(0, 4, 4, menuIconWithText(getResources().getDrawable(R.mipmap.logout), getResources().getString(R.string.action_sign_out))); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle … Read more

Android Lollipop, add popup menu from title in toolbar

You’re going to need to add a Spinner to the Toolbar: <android.support.v7.widget.Toolbar android:id=”@+id/toolbar” android:layout_height=”?attr/actionBarSize” android:layout_width=”match_parent” android:background=”?attr/colorPrimary”> <Spinner android:id=”@+id/spinner_nav” android:layout_width=”wrap_content” android:layout_height=”wrap_content” /> </android.support.v7.widget.Toolbar> You will then need to disable the default title: Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowTitleEnabled(false); You can then retrieve and setup the Spinner as needed in your Activity/Fragment.

How to reduce the gap between navigation icon and toolbar title?

Add app:contentInsetLeft=”0dp” app:contentInsetStart=”0dp” app:contentInsetStartWithNavigation=”0dp” to the ToolBar. Complete Code : <android.support.v7.widget.Toolbar android:id=”@+id/toolbar” android:layout_width=”match_parent” android:layout_height=”?attr/actionBarSize” android:background=”?attr/colorPrimary” app:titleTextAppearance=”@style/Toolbar.TitleText” app:popupTheme=”@style/AppTheme.PopupOverlay” app:contentInsetLeft=”0dp” app:contentInsetStart=”0dp” app:contentInsetStartWithNavigation=”0dp” />

Using Toolbar with Fragments

Fragments don’t have such method setSupportActionBar(). ActionBar is a property of Activity, so to set your toolbar as the actionBar, your activity should extend from ActionBarActivity and then you can call in your Fragment: ((ActionBarActivity)getActivity()).setSupportActionBar(mToolbar); UPDATE If you’re using AppCompatActivity : ((AppCompatActivity)getActivity()).setSupportActionBar(mToolbar);

Toolbar icon tinting on Android

Another option is to use the new support for vector drawables in the support library. See res/xml/ic_search.xml in blog post AppCompat — Age of the vectors Notice the reference to ?attr/colorControlNormal <vector xmlns:android=”…” android:width=”24dp” android:height=”24dp” android:viewportWidth=”24.0″ android:viewportHeight=”24.0″ android:tint=”?attr/colorControlNormal”> <path android:pathData=”…” android:fillColor=”@android:color/white”/> </vector>

Clicking hamburger icon on Toolbar does not open Navigation Drawer

In your ActivityMain.xml, the toolbar is outside of the DrawerLayout. That’s the problem. If you want Toolbar to interact with DrawLayout, Toolbar needs to be a child of DrawerLayout. To fix the problem, make DrawerLayout the root of your activity. Here’s the documentation. The relevant quote is: To add a navigation drawer, declare your user … Read more

How can I fix the Spinner style for Android 4.x placed on top of the Toolbar

I know this is late but I came accross this question when I encountered this problem myself and I found a solution in the BrowseSessionsActivity of the Google I/O 2014 app and adapted it. Layouts toolbar_spinner.xml <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”wrap_content” android:layout_height=”match_parent” android:orientation=”vertical”> <Spinner android:id=”@+id/toolbar_spinner” style=”@style/Widget.MyApp.HeaderBar.Spinner” android:layout_width=”wrap_content” android:layout_height=”match_parent”/> </LinearLayout> toolbar_spinner_item_actionbar.xml <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout … Read more

Seeing message in logs: “app:theme is deprecated”?

Replace app:theme to android:theme but you can have a situation when you are not using app:theme. Check your layout, especially toolbar layout. In my case, I didn’t have app:theme in my layout files. Then take a look at my situation: <android.support.v7.widget.Toolbar xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:styled=”http://schemas.android.com/apk/res-auto” android:id=”@+id/toolbar_actionbar” android:layout_width=”match_parent” android:layout_height=”?attr/actionBarSize” android:background=”?attr/colorPrimary” android:minHeight=”?attr/actionBarSize” styled:popupTheme=”@style/ToolbarDarkPopup” styled:theme=”@style/ActionBarThemeOverlay” /> And I’ve changed this … Read more