Android: TabHost without TabActivity

前端 未结 4 1928
旧巷少年郎
旧巷少年郎 2020-11-27 02:56

I want to create tabs without extending TabActivity. (The reason is that TabActivity cannot handle a custom titlebar as it seems). I have

pu         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 03:37

    Design considerations notwithstanding, the following does not work at all, and the API seems to indicate that setContent(Intent i) is valid. This works when the activity extends TabActivity, however, extending Activity and adding setup() call results in an exception at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:649)

    Funny thing is, the LogCat suggests I forgot to call setup()

    mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup();
    
    Intent tab1Intent = new Intent(this, ActivityOne.class);
    Button tab1View = new Button(this);
    tab1View.setText("Activity 1");
      mTabHost.addTab(mTabHost.newTabSpec("tab_1").setIndicator(tab1View).setContent(tab1Intent));
    

提交回复
热议问题