I tried my own Custom Action bar for getting action bar title centered on the middle. It worked. However, after I added the options menu in Action bar, the title again shifted to the left. What should I do in order to get the title centered on the middle of the action bar? my code is:
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
View cView = getLayoutInflater().inflate(R.layout.custom_actionbar, null);
actionBar.setCustomView(cView);
and my layout is
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@android:color/holo_blue_light"
android:orientation="vertical" >
<TextView
android:id="@+id/apptitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal|center_vertical"
android:gravity="center_horizontal|center_vertical"
android:text="@string/app_name" />