0

I want to center the title in the Actionbar. I have created a custom layout for that it does comes up in the center if home icon is visible but if that is set to false then the title shifts to the left thus not coming up in center.

The actionbar should only have title and menu options and no home icon which will take the user back to the previous screen. I have even tried giving left margin to it but still it doesn't work.

Is there any workaround for this??

<?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" >

<TextView
    android:id="@+id/txtTitle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:ellipsize="end"
    android:maxLines="1"
    android:text="@string/app_name"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@android:color/white"
    android:textSize="@dimen/title_size" />

</RelativeLayout>
thefrugaldev
  • 1,619
  • 4
  • 18
  • 36
  • can you post your custom layout code ? – Haresh Chhelana Oct 07 '13 at 10:18
  • Have added the custom action bar layout above. If onCreateOptions method is commented out or actionBar.setDisplayShowHomeEnabled(false) is not used then it does appear in center. But I want the title and menu options not the home icon. – thefrugaldev Oct 07 '13 at 10:37
  • you can see this link.It can works fine. [http://stackoverflow.com/questions/19244411/center-align-title-in-action-bar-using-styles-in-android][1] – jbas Dec 27 '14 at 00:23

0 Answers0