简体   繁体   English

有没有办法添加标签布局而不让活动扩展TabActivity?

[英]Is there any way to add tab layout without letting the activity to extend TabActivity?

I want to add tabs to the layout of my activity, but I don't want the activity to extend TabActivity. 我想在我的活动布局中添加选项卡,但我不希望活动扩展TabActivity。 The example in http://developer.android.com/resources/tutorials/views/hello-tabwidget.html only gave example of subclass of TabActivity. http://developer.android.com/resources/tutorials/views/hello-tabwidget.html中的示例仅提供了TabActivity的子类示例。

Is there any way I can make it without extending TabActivity? 有没有办法在没有扩展TabActivity的情况下实现它?

Thanks. 谢谢。

I figured it out. 我想到了。

In Xml file I should define TabHost like below: 在Xml文件中,我应该像下面这样定义TabHost:

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

In Java file: 在Java文件中:

public class HelloTest extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TabHost tabHost = (TabHost) findViewById(R.id.mytabhost);
        tabHost.setup();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不让活动扩展TabActivity的情况下添加标签布局? - How to add tab layout without letting the activity to extend TabActivity? 是否有任何好的解决方案分别在TabActivity中为每个活动进行搜索? - Is there any good solution for searching in TabActivity for each activity in tab respectively? 在TabActivity的单个选项卡中重新启动活动? - Restarting an activity in a single tab in a TabActivity? 差异tabActivity和tabhost和选项卡布局 - Difference tabActivity and tabhost and tab Layout 如何防止在TabActivity的第一个选项卡上启动活动? - How to prevent starting the activity at the first tab in a TabActivity? 如何避免在TabActivity的第一个选项卡上启动活动? - How to avoid starting the activity at the first tab in a TabActivity? 触摸选项卡小部件时,TabActivity无法启动活动 - TabActivity not starting activity when tab widget touched 如何通过“活动”(标签)在TabActivity中设置控件的可见性? - How to setVisibility for control in TabActivity from Activity (tab)? 除了TabActivity之外,有什么方法可以为Android 2.2操作系统到Android 4.0操作系统创建基于选项卡的应用程序? - Is there any way to create tab based application for Android 2.2 os to Android 4.0 os except TabActivity? 如何在不扩展TabActivity的情况下显示选项卡视图 - How to display tab view without extending TabActivity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM