Frage

I want to add a custom title bar in a child of FragmentActivity, I have a layout for title bar and this is how I do it.

    final ActionBar actionBar = getActionBar();

    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setCustomView(R.layout.title_bar);

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.addTab(actionBar.newTab().setText("Tab0").setTabListener(this));
    actionBar.addTab(actionBar.newTab().setText("Tab1").setTabListener(this));
    actionBar.addTab(actionBar.newTab().setText("Tab2").setTabListener(this));

but the problem is title bar is showing below the tabs. I want the title bar above the navigation tabs.

this is my title_bar.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/titleBar"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/black" >

    <ImageView
        android:id="@+id/titleBarMenuBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/menu_btn" />


    <TextView
        android:id="@+id/titleBarLocation"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/titleBarMenuBtn"
        android:text="Location"
        android:textColor="@color/white"
        android:textSize="16dip" />


    <TextView
        android:id="@+id/titleBarUpdateDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/titleBarMenuBtn"
        android:layout_alignLeft="@+id/titleBarLocation"
        android:layout_alignParentRight="true"
        android:text="Updated: 30/Jul/2013"
        android:textColor="@color/white" />

</RelativeLayout>

I saw this post but my tabs are showing above title bar.

Thanks

War es hilfreich?

Lösung

Showing the tabs above your custom layout is the intended default behaviour. Though there are ways to override this. I found to post with possible solutions: #1 and #2

Further more the sherlock actionbar seems to behave the same way.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top