no tab selected by default
code is given below, problem is i am not able to remove "Main" tab from the code, as it just closes the application, and that happens because once main tab is removed it selects "call" tab default activity... buh i want to have main view as main activity and call or email or web tab only work when a user click on them
Java code
package com.NVT.android;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
public class MainTabActivity extends TabActivity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_activity_layout);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, Main.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("main").setIndicator("Main",
res.getDrawable(R.drawable.ic_tab_artists_grey))
.setContent(intent);
tabHost.addTab(spec);
TabHost host=getTabHost();
host.addTab(host.newTabSpec("one")
.setIndicator("Call")
.setContent(new Intent(this, CallService.class)));
host.addTab(host.newTabSpec("two")
.setIndicator("Email")
.setContent(new Intent(this, EmailService.class)));
host.addTab(host.newTabSpec("three")
.setIndicator("Web")
.setContent(new Intent(this, WebService.class)));
}
}
XML coding
<?xml version="1.0" encoding="utf-8"?>
<TabHo开发者_开发知识库st 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"
android:padding="5dp">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"></FrameLayout>
</RelativeLayout>
</LinearLayout>
</TabHost>
Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.NVT.android"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Main"
android:label="@string/app_name">
<!-- <intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter> -->
</activity>
<activity android:name=".MainTabActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Courses">
</activity>
<activity android:name=".CampusMap">
</activity>
<activity android:name=".GettingHere">
</activity>
<activity android:name=".ILoveNescot">
</activity>
<activity android:name=".FurtherEducationCourses">
</activity>
<activity android:name=".HigherEducationCourses">
</activity>
<activity android:name=".EmployersTrainingCourses">
</activity>
<activity android:name=".WebService">
</activity>
<activity android:name=".CallService">
</activity>
<activity android:name=".EmailService">
</activity>
</application>
<uses-sdk android:minSdkVersion="9" />
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
</manifest>
Try this How to allow user to Add and Delete Tabs in an android application
精彩评论