当前位置: 动力学知识库 > 问答 > 编程问答 >

android - override an activity on another

问题描述:

1This is my code snippet

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

The Intent is not overriding the main activity.

how am i supposed to override it.

This is my manifest

<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>`

From my image it is showing that when i press the button the activit is showing in particular portion and the last activity remains same in the activity.So how to override that activty when i press the tab button.

网友答案:

Simply declare you tab's activities as per below -

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

And, have a look at TabLayout tutorial.

分享给朋友:
您可能感兴趣的文章:
随机阅读: