Android - 使用 TabHost 制作子选项卡

发布于 2024-12-11 13:53:08 字数 80 浏览 0 评论 0原文

是否可以在 TabHost 制作的选项卡中创建子选项卡?如果是这样,怎么办?在这种情况下,我无法找到任何有价值的资源或帮助。

谢谢

is it possible to create subtabs in tabs made by TabHost? If so, how? I was not able to find any valuable source or help in this case.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌上芳菲 2024-12-18 13:53:08

可以将 TabActivity 放入 Tab 中。

假设您有带有两个 TabMainTabActivity。第一个 Tab 可以保存 FirstSubTabActivity,第二个 Tab 可以保存 SecondSubTabActivity

下面是一个示例:

主要活动:

public class MainTabActivity extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TabHost tabHost = getTabHost();
        TabHost.TabSpec spec;
        Intent intent;

        intent = new Intent().setClass( this, FirstSubTabActivity.class );
        spec = tabHost.newTabSpec( "FirstTab" ).setIndicator( "One" ).setContent( intent );
        tabHost.addTab( spec );

        intent = new Intent().setClass( this, SecondSubTabActivity.class );
        spec = tabHost.newTabSpec( "SecondTab" ).setIndicator( "Two" ).setContent( intent );
        tabHost.addTab( spec );
    }
}

第一个子活动:

public class FirstSubTabActivity extends TabActivity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);

       TabHost tabHost = getTabHost();
       TabHost.TabSpec spec;
       Intent intent;

       intent = new Intent().setClass( this, SomeActivity.class );
       spec = tabHost.newTabSpec( "SubTab" ).setIndicator( "One" ).setContent( intent );
       tabHost.addTab( spec );

       intent = new Intent().setClass( this, SomeOtherActivity.class );
       spec = tabHost.newTabSpec( "AnotherSubTab" ).setIndicator( "Two" ).setContent( intent );
       tabHost.addTab( spec );
   }
}

第二个子活动:

public class SecondSubTabActivity extends TabActivity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);

       TabHost tabHost = getTabHost();
       TabHost.TabSpec spec;
       Intent intent;

       intent = new Intent().setClass( this, SomeThirdActivity.class );
       spec = tabHost.newTabSpec( "ThirdSubTab" ).setIndicator( "One" ).setContent( intent );
       tabHost.addTab( spec );

       intent = new Intent().setClass( this, SomeFourthActivity.class );
       spec = tabHost.newTabSpec( "FourthSubTab" ).setIndicator( "Two" ).setContent( intent );
       tabHost.addTab( spec );
   }
}

It is possible to put a TabActivity inside a Tab.

Say you have MainTabActivity with two Tabs. First Tab can then hold FirstSubTabActivity and the second Tab could hold SecondSubTabActivity.

Here is an example:

Main activity:

public class MainTabActivity extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TabHost tabHost = getTabHost();
        TabHost.TabSpec spec;
        Intent intent;

        intent = new Intent().setClass( this, FirstSubTabActivity.class );
        spec = tabHost.newTabSpec( "FirstTab" ).setIndicator( "One" ).setContent( intent );
        tabHost.addTab( spec );

        intent = new Intent().setClass( this, SecondSubTabActivity.class );
        spec = tabHost.newTabSpec( "SecondTab" ).setIndicator( "Two" ).setContent( intent );
        tabHost.addTab( spec );
    }
}

First subactivity:

public class FirstSubTabActivity extends TabActivity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);

       TabHost tabHost = getTabHost();
       TabHost.TabSpec spec;
       Intent intent;

       intent = new Intent().setClass( this, SomeActivity.class );
       spec = tabHost.newTabSpec( "SubTab" ).setIndicator( "One" ).setContent( intent );
       tabHost.addTab( spec );

       intent = new Intent().setClass( this, SomeOtherActivity.class );
       spec = tabHost.newTabSpec( "AnotherSubTab" ).setIndicator( "Two" ).setContent( intent );
       tabHost.addTab( spec );
   }
}

Second subactivity:

public class SecondSubTabActivity extends TabActivity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);

       TabHost tabHost = getTabHost();
       TabHost.TabSpec spec;
       Intent intent;

       intent = new Intent().setClass( this, SomeThirdActivity.class );
       spec = tabHost.newTabSpec( "ThirdSubTab" ).setIndicator( "One" ).setContent( intent );
       tabHost.addTab( spec );

       intent = new Intent().setClass( this, SomeFourthActivity.class );
       spec = tabHost.newTabSpec( "FourthSubTab" ).setIndicator( "Two" ).setContent( intent );
       tabHost.addTab( spec );
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文