title: How to set the title of action bar in center in Android
body: <p>Hello I am working on demo app where I need to set the title in <code>ActionBar</code> 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.</p>
  
  <p><a href="https://stackoverflow.com/a/21770534/2455259">https://stackoverflow.com/a/21770534/2455259</a> , <a href="https://stackoverflow.com/a/19244633/2455259">https://stackoverflow.com/a/19244633/2455259</a></p>
  
  <p>but nothing worked for me. Is there any way to set the title of <code>ActionBar</code> to center in Android using appcompat ?</p>
  
  <p>I am doing this like below but still title is in left side.</p>
  
  <p>center_action_bar_title.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;TextView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:textSize="18sp" /&gt;
  </code></pre>
  
  <p>In Activity</p>
  
  <pre><code>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);
  </code></pre>