android - 调用新 Activity 时不显示标签栏

标签 android android-fragments android-tabhost android-tabs

我的代码

 View view = getLocalActivityManager().startActivity("main_jobs", 
                        new Intent(context,Job_Description.class)
                        .putExtra("line", str_line).putExtra("limit",str_limit)
                        .putExtra("limit",""+0)
                        .putExtra("Alert", false)
                        .putExtra("str_location", str_loc)
                        .putExtra("str_Descrption",str_descjob)
                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                        .getDecorView();
                                              setContentView(view);

我正在使用此代码打开带有选项卡的新 Activity ,但未显示选项卡栏并且 没有任何错误得到 请帮助我如何显示标签栏以打开新 Activity

提前致谢

最佳答案

示例示例: 在这里考虑三个选项卡 首先在MainActivity.java中

public class MainActivity extends TabActivity {

    private static final String TAB1 = "TAB1";
    private static final String TAB2 = "TAB2";
    private static final String TAB3 = "TAB3";

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

        TabHost tabHost = getTabHost();


        TabSpec tab1 = tabHost.newTabSpec(TAB1);
        tab1.setIndicator(TAB1);
        Intent Intent1 = new Intent(this, Tab1.class);
        tab1.setContent(Intent1);


        TabSpec tab2 = tabHost.newTabSpec(TAB2);
        tab2.setIndicator(TAB2);
        Intent Intent2 = new Intent(this, Tab2.class);
        tab2.setContent(Intent2);


        TabSpec tab3 = tabHost.newTabSpec(TAB3);
        tab3.setIndicator(TAB3);
        Intent Intent3 = new Intent(this, Tab3.class);
        tab1.setContent(Intent3);


        tabHost.addTab(tab1); 
        tabHost.addTab(tab2); 
        tabHost.addTab(tab3); 
    }
}

主.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:layout_height="fill_parent">
    <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="64dp" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>
    </LinearLayout>
</TabHost>

然后是三个类 Tab1.java , Tab2.java 和 Tab3.java 以及该类的三个 xml 文件。

试一试再说。

关于android - 调用新 Activity 时不显示标签栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20897268/

相关文章:

android - 如何使用 MaterialComponents 正确显示 DatePickerDialog?

Android TabBar - 随着键盘打开而向上滑动

android - Android TabActivity 中奇怪的选项菜单行为

android - “取消选择”TabHost 中的选项卡

Android facebook 登录 Spring Social web 应用

android - 单击电子邮件链接时出现不受支持的操作错误

android - 使用 ibeacon 构建简单的室内定位

android - 一个 Activity 就够了,为什么要用两个 Activity 和两个 fragment

android - 如何在相应 fragment 打开时设置菜单项的可见性?

android - Here Maps - 在 TabLayout 的 fragment 中使用 MapFragment