有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java当我使用TabActivity 安卓时,TabActivity类型已被弃用

在我的安卓应用程序中,我想使用TabHost更改使用选项卡的活动,下面是我设置tab控件的.xaml.页面代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
                 xmlns:tools="http://schemas.安卓.com/tools"
                  安卓:layout_width="match_parent"
                  安卓:layout_height="match_parent">

<TabHost 
    安卓:id="@+id/tabhost"
    安卓:layout_width="fill_parent"
    安卓:layout_height="fill_parent"
    安卓:paddingBottom="@dimen/activity_vertical_margin"
    安卓:paddingLeft="@dimen/activity_horizontal_margin"
    安卓:paddingRight="@dimen/activity_horizontal_margin"
    安卓:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.hakslogin.LoginSuccess">
    <LinearLayout
        安卓:orientation="vertical"
        安卓:layout_width="fill_parent"
        安卓:layout_height="fill_parent">
        <HorizontalScrollView 
            安卓:id="@+id/horizontalScrollView1"
            安卓:layout_width="fill_parent"
            安卓:layout_height="wrap_content" 
            安卓:fillViewport="true">
            <TabWidget 安卓:id="@安卓:id/tabs"
               安卓:layout_width="fill_parent"
               安卓:layout_height="wrap_content"/>
        </HorizontalScrollView>
        <FrameLayout 安卓:id="@安卓:id/tabcontent"
            安卓:layout_width="fill_parent"
            安卓:layout_height="fill_parent">

        </FrameLayout>
    </LinearLayout>
</TabHost>

<RelativeLayout 
    安卓:layout_width="wrap_content"
    安卓:layout_height="match_parent"
    安卓:paddingBottom="@dimen/activity_vertical_margin"
    安卓:paddingLeft="@dimen/activity_horizontal_margin"
    安卓:paddingRight="@dimen/activity_horizontal_margin"
    安卓:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.hakslogin.LoginSuccess" >

    <View
        安卓:id="@+id/view1"
        安卓:layout_width="400dp"
        安卓:layout_height="30dp"
        安卓:background="#c0c0c0" />

    <TextView
        安卓:id="@+id/tv_home"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignTop="@+id/btn_backlogin"
        安卓:layout_centerHorizontal="true"
        安卓:gravity="top|center"
        安卓:textColor="#000000"
        安卓:text="Home" />

    <Button
        安卓:id="@+id/btn_backlogin"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignParentLeft="true"
        安卓:layout_alignParentTop="true"
        安卓:layout_marginLeft="14dp"
        安卓:background="@null"
        安卓:gravity="top|left"
        安卓:text="Login" />

    <TextView
        安卓:id="@+id/tv_childform"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_below="@+id/btn_backlogin"
        安卓:layout_centerHorizontal="true"
        安卓:layout_marginTop="70dp"
        安卓:textColor="#000000"
        安卓:text="Child Form" />

    <Button
        安卓:id="@+id/btn_child"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_below="@+id/tv_childform"
        安卓:layout_centerHorizontal="true"
        安卓:layout_marginTop="60dp"
        安卓:background="@null"
        安卓:textColor="#003EFF"
        安卓:text="Child" />

</RelativeLayout>

</RelativeLayout>

以下是我的活动:

package com.example.hakslogin;

import 安卓.support.v7.app.ActionBarActivity;
import 安卓.os.Bundle;
import 安卓.view.Gravity;
import 安卓.view.Menu;
import 安卓.view.MenuItem;
import 安卓.view.View;
import 安卓.widget.ArrayAdapter;
import 安卓.widget.Button;
import 安卓.widget.TabHost;
import 安卓.widget.Toast;
import 安卓.content.Context;
import 安卓.content.Intent;
import 安卓.graphics.Color;
import 安卓.view.View.OnClickListener;
import 安卓.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 安卓.app.TabActivity;
public class LoginSuccess extends TabActivity{ //ActionBarActivity {

上面的错误已删除,但我得到另一个错误

The type TabActivity is deprecated

我如何解决这个问题,请建议我,等待回复

谢谢


共 (0) 个答案