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 shift
First, create a .xml file like this: (action_bar.xml)
And then, in your activity:
View view = getLayoutInflater().inflate(R.layout.action_bar, null);
ActionBar.LayoutParams params = new ActionBar.LayoutParams(
ActionBar.LayoutParams.WRAP_CONTENT,
ActionBar.LayoutParams.MATCH_PARENT,
Gravity.CENTER);
TextView Title = (TextView) view.findViewById(R.id.actionbar_title);
Title.setText("Your Title");
getSupportActionBar().setCustomView(view,params);
getSupportActionBar().setDisplayShowCustomEnabled(true); //show custom title
getSupportActionBar().setDisplayShowTitleEnabled(false); //hide the default title
I've tried a lot of solutions and only this one works. Hope it helps you.