I managed to center the title of the ABS using a custom view but the home button is gone. How can this be solved? Is the only way to do it to put this home button in the custom view? (To be clear: the home button should be on the left not in the center)
Custom view:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="@android:color/transparent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello"/>
</LinearLayout>
Activity code:
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.widget_actionbar_title);
getSupportActionBar().setHomeButtonEnabled(true);
I had to add this code to make it work: