I would like to center the title in the action bar, having action icons next to it (and ignoring them to set gravity).
I would like to have this: 
Instead, I have the following: 
Here is my code:
ActionBar actionBar = getSupportActionBar(); ActionBar.LayoutParams params = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT); actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.top_bar)); actionBar.setCustomView(LayoutInflater.from(this).inflate(R.layout.actionbar_layout, null), params); actionBar.setDisplayShowCustomEnabled(true); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowTitleEnabled(false);
My layout:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="match_parent" android:padding="8dp" android:src="@drawable/launcher_icon" /> <TextView android:id="@+id/actionbar_title" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:maxHeight="1dp" android:maxLines="1" android:paddingLeft="48dp" android:paddingRight="48dp" android:text="Bacon ipsum" android:textColor="#777777" android:textSize="20sp" /> </RelativeLayout>
So my problem is that centering the heading only works if I have 0 taskbar elements next to it, as soon as I add the element, the centering will be screwed up. It would also be great if I could use the free access button with it (which also twists the centering).
Any help would be appreciated.
I do not want to implement my own control element / button logic.
Tamas source share