覆盖另一个活动

时间:2012-08-30 06:51:17

标签: android android-intent android-widget android-tabhost

1这是我的代码段

TabHost tabHost = getTabHost();    
TabSpec aboutus = tabHost.newTabSpec("About us");
aboutus.setIndicator("___", getResources().getDrawable(R.drawable.icon_aboutus_tab));
Intent photosIntent = new Intent(getApplicationContext(), readmore.class);

aboutus.setContent(photosIntent);
TabSpec contactus = tabHost.newTabSpec("Contact us");
// setting Title and Icon for the Tab
contactus.setIndicator("___", getResources().getDrawable(R.drawable.icon_contactus_tab));
Intent songsIntent = new Intent(getApplicationContext(), contactus.class);
contactus.setContent(songsIntent);
TabSpec orderhistory = tabHost.newTabSpec("Order history");
orderhistory.setIndicator("___", getResources().getDrawable(R.drawable.icon_orderhistory_tab));
Intent videosIntent = new Intent(getApplicationContext(), readmore.class);
orderhistory.setContent(videosIntent);
TabSpec home = tabHost.newTabSpec("Home");
home.setIndicator("___", getResources().getDrawable(R.drawable.icon_home_tab));
Intent homeIntent = new Intent(getApplicationContext(), Mainpage.class);
homeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
homeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
homeIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
home.setContent(homeIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(aboutus); // Adding about us tab
tabHost.addTab(contactus); // Adding contact us tab
tabHost.addTab(orderhistory); // Adding order history tab
tabHost.addTab(home);

This is my screen shot on emulato

意图不会覆盖主要活动。 我该如何覆盖呢。

这是我的清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidhive.xmlparsing"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.READ_CONTACTS"/>
 <uses-permission android:name="android.permission.INTERNET" />
 <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
 <uses-permission android:name="android.permission.CLEAR_APP_CACHE"/>
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
    android:icon="@drawable/zaggleicon"
    android:label="@string/app_name"
    android:name=".MyApplication"
    android:theme="@android:style/Theme.Light" 

    >`<activity
        android:label="@string/app_name"
        android:name=".AndroidTabLayoutActivity" >
        <intent-filter >

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>`<activity
        android:label="@string/app_name"
        android:name=".readmore" >
        <intent-filter >

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>` <activity android:name=".Mainpage">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>`<activity
        android:label="@string/app_name"
        android:name=".contactus" >
        <intent-filter >

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>`

从我的图像中可以看出,当我按下按钮时,活动显示在特定部分,最后一个活动在活动中保持相同。所以当我按下标签按钮时如何覆盖该活动。

1 个答案:

答案 0 :(得分:0)

只需按以下方式声明标签的活动 -

<activity
    android:label="@string/app_name"
    android:name=".readmore"> </activity>

<activity android:name=".Mainpage"></activity>

<activity
    android:label="@string/app_name"
    android:name=".contactus" ></activity>

并查看TabLayout教程。