Hello I am working on demo app where I need to set the title in ActionBar
in center of it. I have tried some posts of SO that did not work for me. I am trying on Android 4.3 phone.
https://stackoverflow.com/a/21770534/2455259 , https://stackoverflow.com/a/19244633/2455259
but nothing worked for me. Is there any way to set the title of ActionBar
to center in Android using appcompat ?
I am doing this like below but still title is in left side.
center_action_bar_title.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp" />
In Activity
TextView customView = (TextView)
LayoutInflater.from(getActivity()).inflate(R.layout.center_action_bar_title,
null);
ActionBar.LayoutParams params = new
ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT,
ActionBar.LayoutParams.MATCH_PARENT, Gravity.CENTER);
customView.setText(text);
((ActionBarActivity)getActivity()).getSupportActionBar().setCustomView(customView, params);