【问题标题】:Tabview to follow all activitiesTabview 跟踪所有活动
【发布时间】:2011-12-20 10:22:46
【问题描述】:

我是 android 新手,我正在尝试使用 tabhost 开发一个简单的应用程序。我希望 tabhost 出现在我的所有活动中。我有 5 个标签和 6-7 个活动,我希望它们都显示在这五个标签中。

在这里我创建了我的 tabactivity:

<?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" >

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >


    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@android:id/tabs" />

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"

         />
</RelativeLayout>

</TabHost>

我在这里添加标签:

    TabSpec tabSpec = mTabHost.newTabSpec("tab_test1");
    tabSpec.setIndicator("Map",res.getDrawable(R.drawable.world));
    Context ctx = this.getApplicationContext();
    Intent i = new Intent(ctx, DealFinderActivity.class);
    tabSpec.setContent(i); 
    mTabHost.addTab(tabSpec); 

    mTabHost.getTabWidget().setBackgroundColor(Color.GRAY);

    mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator
            ("List Deals",res.getDrawable(R.drawable.database))
            .setContent(new Intent(this,ListDeals.class)));

    //      TextView textView = (TextView) findViewById(R.id.textview3);
    //      textView.setText("hello");
    mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("Favorites",
            res.getDrawable(R.drawable.heart)).setContent(
                    new Intent(this, ListDeals.class)));

    mTabHost.addTab(mTabHost.newTabSpec("tab_test4").setIndicator("Settings",
            res.getDrawable(R.drawable.preferences)).setContent(
                    new Intent(this, DealDescription.class)));

    mTabHost.addTab(mTabHost.newTabSpec("tab_test5").setIndicator("About",
            res.getDrawable(R.drawable.newspaper)).setContent(
                    new Intent(this, DealDescription.class)));

在 ListDeals.class 中,我使用它来更改新活动:

        Intent myIntent = new Intent(getApplicationContext(), 
                DealMyAss.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        getApplication().startActivity(myIntent);

但是这里的tabview消失了??

有什么想法可以保留标签视图吗??

提前致谢

【问题讨论】:

    标签: android tabview


    【解决方案1】:

    ActivityGroup 就是你要找的。​​p>

    顾名思义,它在一个选项卡中嵌入了多个活动。 通过例子。一个是here

    为每个选项卡创建一个 ActivityGroup。

    【讨论】:

    • 只想补充一点,在 ICS 中不推荐使用 ActivityGroups。最好使用 Fragments。
    • 是的,我按照示例进行了操作,它工作得很好,但是我有一个 Map 类,其中有可点击的叠加层,这些叠加层位于 MyItemizedOverlay 中,并且在该类中有一个 onTap 方法来更改类,在那堂课上我不能让它改变??
    • 尝试从另一个类 java.lang.ClassCastException: android.app.application 更改时出现此错误
    • 它的代码:protected boolean onBalloonTap(int index, OverlayItem item) { Intent previewMessage = new Intent(c, DealDescription.class); TabGroupActivity parentActivity = (TabGroupActivity)c; parentActivity.startChildActivity("ArrowsActivity", previewMessage);返回真;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多