【问题标题】:Tab bar not showing when call new activity调用新活动时标签栏不显示
【发布时间】:2014-01-03 05:38:42
【问题描述】:

我的代码

 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);

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

提前致谢

【问题讨论】:

  • 你正在使用 tabhost ryt 吗?
  • 是的,我正在使用 Tabhost
  • 你有多少个标签页?
  • 我只有四个标签,我正在从登录类调用 Jobsearch 类,这两个类都不在标签中,但我想显示标签栏。
  • 在此处发布代码或将其放入 googledrive 并提供链接。没有代码什么都做不了。

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


【解决方案1】:

示例: 在这里考虑三个选项卡 首先在 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); 
    }
}

main.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 文件。

试试看再说。

【讨论】:

  • 感谢重播,它工作正常,但我还有两个类,如 Login.class 和 Jobsearc.class 我正在从 login.class 调用 jobsearch.class 并希望使用标签栏打开 Jobsearch.class跨度>
  • 只搞清楚一件事。每个选项卡都有单独的活动。如果您单击该选项卡,它会显示。因此,您需要向您的类 login.class 和 jobsearch.class 显示选项卡,然后您需要再创建两个选项卡,或者您需要在该 xml 文件中创建另一个选项卡小部件。
  • 不,我不想在标签栏中显示此活动,我只想在打开求职类时显示带有上一个菜单的标签
【解决方案2】:

当您转移到一项新活动时,您正在构建一个全新的视图,这意味着您刚刚所在的视图被丢弃并被这个新视图所取代。如果你想要标签栏,你需要像第一个活动一样将它构建到这个新活动中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-07
    • 2020-08-31
    • 2018-01-20
    • 1970-01-01
    • 1970-01-01
    • 2015-08-07
    • 2021-09-04
    相关资源
    最近更新 更多