开发者

Can i have a view stub on top of TabActivity?

I开发者_Go百科 am having four tabs in my tab activity and I need a toolbar with three buttons on top of tabactivity irrespective of current tab selection.

Can I use viewstub for this?

Could anyone help me to achieve this?


<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/tabhost" 
     android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent">
    <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:id="@+id/header">
        <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:text="woopra" android:textColor="#ffffff" android:textSize="36sp"
            android:textStyle="bold"/>
    </LinearLayout>       
    <FrameLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
        <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" 
            android:layout_height="wrap_content" android:visibility="gone"/>            
        <LinearLayout android:layout_width="fill_parent" android:layout_height="64dip">
            <Button android:layout_height="fill_parent" android:layout_width="0dip" 
                android:layout_weight="1.0" android:id="@+id/dashboard_tab" 
                android:onClick="tabHandler" android:text="Dashboard"/>
            <Button android:layout_height="fill_parent" android:layout_width="0dip" 
                android:layout_weight="1.0" android:id="@+id/visitors_tab" 
                android:onClick="tabHandler" android:text="Vistors"/>
            <Button android:layout_height="fill_parent" android:layout_width="0dip" 
                android:layout_weight="1.0" android:id="@+id/chat_tab" android:onClick="tabHandler"
                android:text="Chat"/>
            <Button android:layout_height="fill_parent" android:layout_width="0dip" 
                android:layout_weight="1.0" android:id="@+id/reports_tab" 
                android:onClick="tabHandler" android:text="Reports"/>
        </LinearLayout> 
    </FrameLayout>
    <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="0dip"
                 android:layout_weight="1.0"/>
</LinearLayout>

Here the framelayout with id 'tabcontent' is where the content of our tab goes to. What ever you put outside this framwlayout will be in the tab activity irrespective of the tab selected.

If you look on the top of the xml you can see a linearlayout with id 'header'. This is a heading layout that I made which will always be visible in the tab layout. You can do the same to create a toolbar by putting buttons instead of textviews like ive done.


Just put your toolbar in the layout, what's the problem?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜