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” />

How do I style appcompat-v7 Toolbar like Theme.AppCompat.Light.DarkActionBar?

The recommended way to style the Toolbar for a Light.DarkActionBar clone would be to use Theme.AppCompat.Light.DarkActionbar as parent/app theme and add the following attributes to the style to hide the default ActionBar: <style name=”AppTheme” parent=”Theme.AppCompat.Light.DarkActionBar”> <item name=”windowActionBar”>false</item> <item name=”windowNoTitle”>true</item> </style> Then use the following as your Toolbar: <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” … Read more

Change status bar color with AppCompat ActionBarActivity

I’m not sure I understand the problem. I you want to change the status bar color programmatically (and provided the device has Android 5.0) then you can use Window.setStatusBarColor(). It shouldn’t make a difference whether the activity is derived from Activity or ActionBarActivity. Just try doing: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); … Read more

Expand/Collapse Lollipop toolbar animation (Telegram app)

Edit : Since the release of the Android Design support library, there’s an easier solution. Check joaquin’s answer — Here’s how I did it, there probably are many other solutions but this one worked for me. First of all, you have to use a Toolbar with a transparent background. The expanding & collapsing Toolbar is … 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 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 Toolbar Adding Menu Items for different fragments

Add similar code to your fragments: @Override public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.library_fragment, parent, false); setHasOptionsMenu(true); return v; } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.your_menu_xml, menu); super.onCreateOptionsMenu(menu, inflater); } This way you can customize the menu for your fragments.

Add elevation/shadow on toolbar for pre-lollipop devices

For Android 5.0 and above : AppBarLayout automatically provides/gives shadow in the layout. You can also increase the elevation of the AppBarLayout by app:elevation=”4dp”. For Pre-Lollipop : You can use the following link: https://github.com/vipulasri/Toolbar-Elevation-Pre-Lollipop Note: Toolbar also supports elevation to it, using android:elevation=”4dp” New Update: In Appcompat v24.0.0, you can not set elevation to AppBarLayout … Read more