开发者

Show tabbar when new activity starts

I wrote a 开发者_如何学JAVAsimple Android program with 2 tabs. Tab 1 has a button which will open a new window. But I realized that when opening this new window, the Android tab bar will be hidden.

I'd like to always show the Android tab bar when new activity starts ie show tab bar for all activity


Basicly, you need to create framelayout, which will host your new activities.

Here is tabs.xml

<?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:orientation="vertical"
    android:layout_height="fill_parent">
   <ScrollView
      android:id="@+id/ScrollView01"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:scrollbars="vertical"
      android:background="@drawable/bbg">
      <LinearLayout
         android:orientation="vertical"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent">
         <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#000000"/>
         <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>
      </LinearLayout>
   </ScrollView>
</TabHost>

And here is TabsActivity:

   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.tabs);

      Resources res = getResources(); 
      TabHost tabHost = getTabHost();  
      TabHost.TabSpec spec;  
      Intent intent;  
      intent = new Intent().setClass(this, RegistrationActivity.class);
      spec = tabHost.newTabSpec("registration").setIndicator("Регистрация",
                        res.getDrawable(R.drawable.ic_tab_registration))
                        .setContent(intent);
      tabHost.addTab(spec);
      intent = new Intent().setClass(this, LoginActivity.class);
      spec = tabHost.newTabSpec("login").setIndicator("Логин",
            res.getDrawable(R.drawable.ic_tab_login))
        .setContent(intent);
      tabHost.addTab(spec);
      tabHost.setCurrentTab(0);


   }

this example will create 2 tabs, and 2 activities. Tap on any tap will start activity. Tabs will be always on top of screen.

UPD.

ActivityGroups may help you http://blog.henriklarsentoft.com/2010/07/android-tabactivity-nested-activities/


Use THis to start the new Activity

View view = getLocalActivityManager().startActivity("tab1", new Intent(this,tab1.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();

setContentView(view);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜