1

enter image description here

Would IDEALLY, like an icon either side and the text to be independently centered. as appose to being pushed by the icon out of line.

    getSupportActionBar().setCustomView(R.layout.action_bar);
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:orientation="horizontal" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center_horizontal"
        android:gravity="center_horizontal|center_vertical"
        android:text="LLabel text"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#000"
        android:textColorHint="#ffffff" >

    </TextView>
</RelativeLayout>
Broak
  • 4,161
  • 4
  • 31
  • 54

1 Answers1

0
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:background="@android:color/darker_gray">

    <ImageView
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:src="@android:drawable/ic_menu_gallery"
        android:layout_gravity="center"
        android:layout_weight="1.3"/>

    <FrameLayout
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_weight="7.4">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:text="Custom Action Bar"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#000"
            android:textColorHint="#ffffff" >

    </FrameLayout>

    <ImageView
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:src="@android:drawable/ic_menu_gallery"
        android:layout_gravity="center"
        android:layout_weight="1.3"/>

</LinearLayout>

This is the result I get with the above layout:

Custom Action Bar

Please use the complete layout as custom. Ignore setHomeAsUp and setTitle.

Put in custom click listeners and you are good to go.

mipreamble
  • 1,415
  • 12
  • 17
  • I'd need to retain the original icon, as apposed to an imageview with click listeners, for navigation drawer purposes etc.. – Broak Nov 26 '13 at 17:25
  • In ImageView use android:src="@android:drawable/ic_launcher" to use the app_icon. The only difference is implementation is you wont use the general menu item click but the custom onclick. – mipreamble Nov 26 '13 at 19:30
  • i was referring to the toggle icon that its put in place by the navigation drawer, i.e. the animation of it etc.. – Broak Nov 26 '13 at 23:30