Display Back Arrow on Toolbar

If you are using an ActionBarActivity then you can tell Android to use the Toolbar as the ActionBar like so: Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar); setSupportActionBar(toolbar); And then calls to getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); will work. You can also use that in Fragments that are attached to ActionBarActivities you can use it like this: ((ActionBarActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); ((ActionBarActivity) … Read more

Android transparent status bar and actionbar

I’m developing an app that needs to look similar in all devices with >= API14 when it comes to actionbar and statusbar customization. I’ve finally found a solution and since it took a bit of my time I’ll share it to save some of yours. We start by using an appcompat-21 dependency. Transparent Actionbar: values/styles.xml: … Read more

Android API 21 Toolbar Padding

The left inset is caused by Toolbar’s contentInsetStart which by default is 16dp. Change this to 72dp to align to the keyline. Update for support library v24.0.0: To match the Material Design spec there’s an additional attribute contentInsetStartWithNavigation which by default is 16dp. Change this if you also have a navigation icon.

Android toolbar center title and custom font

To use a custom title in your Toolbar all you need to do is remember is that Toolbar is just a fancy ViewGroup so you can add a custom title like so: <android.support.v7.widget.Toolbar android:id=”@+id/toolbar_top” android:layout_height=”wrap_content” android:layout_width=”match_parent” android:minHeight=”?android:attr/actionBarSize” android:background=”@color/action_bar_bkgnd” app:theme=”@style/ToolBarTheme” > <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Toolbar Title” android:layout_gravity=”center” android:id=”@+id/toolbar_title” /> </android.support.v7.widget.Toolbar> This means that you can style … Read more

This Activity already has an action bar supplied by the window decor

I think you’re developing for Android Lollipop, but anyway include this line: <item name=”windowActionBar”>false</item> to your theme declaration inside of your app/src/main/res/values/styles.xml. Also, if you’re using AppCompatActivity support library of version 22.1 or greater, add this line: <item name=”windowNoTitle”>true</item> Your theme declaration may look like this after all these additions: <!– Base application theme. –> … Read more