在我的Android应用程序中,我想使用TabHost
使用标签更改活动,下面是我的.xaml.
页面代码,其中我设置tab
控件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabHost
android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.hakslogin.LoginSuccess">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</HorizontalScrollView>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</FrameLayout>
</LinearLayout>
</TabHost>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.hakslogin.LoginSuccess" >
<View
android:id="@+id/view1"
android:layout_width="400dp"
android:layout_height="30dp"
android:background="#c0c0c0" />
<TextView
android:id="@+id/tv_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/btn_backlogin"
android:layout_centerHorizontal="true"
android:gravity="top|center"
android:textColor="#000000"
android:text="Home" />
<Button
android:id="@+id/btn_backlogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="14dp"
android:background="@null"
android:gravity="top|left"
android:text="Login" />
<TextView
android:id="@+id/tv_childform"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_backlogin"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp"
android:textColor="#000000"
android:text="Child Form" />
<Button
android:id="@+id/btn_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_childform"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:background="@null"
android:textColor="#003EFF"
android:text="Child" />
</RelativeLayout>
</RelativeLayout>
以下是我的活动:
package com.example.hakslogin;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.Toast;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.View.OnClickListener;
import android.widget.TabHost.TabSpec;
public class LoginSuccess extends ActionBarActivity {
Button btn_backlogin;
Button btn_child;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_success);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intentAndroid = new Intent().setClass(this, AddChildActivity.class);
spec = tabHost.newTabSpec("Add Child")
.setIndicator("", null)
.setContent(intentAndroid);
tabHost.addTab(spec);
Intent intentApple = new Intent().setClass(this, AddItemActivity.class);
spec = tabHost.newTabSpec("Add Item")
.setIndicator("Add Item", null)
.setContent(intentApple);
tabHost.addTab(spec);
Intent intentWindows = new Intent().setClass(this, QuestionActivity.class);
spec = tabHost.newTabSpec("Question")
.setIndicator("", null)
.setContent(intentWindows);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
}
但是我在这一行TabHost tabHost = getTabHost();
:
The method getTabHost() is undefined for the type LoginSuccess
为了解决这个问题,我将如下所示:
import android.app.TabActivity;
public class LoginSuccess extends TabActivity{ //ActionBarActivity {
以上错误已删除,但我收到了其他错误
The type TabActivity is deprecated
如何解决此问题,请提示我,等待回复。
由于