java - Android - android.widget.TabHost 无法转换为 android.support.v4.app.FragmentTabHost

标签 java android android-tabhost

我是 Android 新手。我正在尝试设置一个简单的 TabHost View 。

这是我的 xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout 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">

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

                <TabWidget
                    android:id="@+id/tabs"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                     android:background="#160203" />

                <FrameLayout
                    android:id="@+id/tabcontent"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"/>

            </LinearLayout>

        </TabHost>

</FrameLayout>

这是我的java代码:

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;

public class Tabhost extends FragmentActivity {

    private FragmentTabHost tabHost;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tabhost);

        tabHost = (FragmentTabHost) findViewById(R.id.tabhost);
        tabHost.setup(this, getSupportFragmentManager(), R.id.tabcontent);

        tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Articulos"),
                ArticulosFragment.class, null);
        tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Tutoriales"),
                TutorialesFragment.class, null);
        tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("Cursos"),
                CursosFragment.class, null);


    }
}

但应用程序崩溃并显示此错误消息(我真的不知道这是什么意思):

enter image description here

你认为哪里可能是错的?

最佳答案

改用:

<android.support.v4.app.FragmentTabHost
     android:id="@+id/tabhost"
     android:layout_width="fill_parent"
      android:layout_height="fill_parent">

(...)

</android.support.v4.app.FragmentTabHost>

关于java - Android - android.widget.TabHost 无法转换为 android.support.v4.app.FragmentTabHost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26365128/

相关文章:

java - Android检查文件错误 “Type mismatch: inferred type is Context but Path! was expected”

java - 使用对话框模式更新 Wicket 面板

java - 效率 - 在等待变量更改的循环中使用 Thread.yield

android - 编程新手 - 在指定位置找不到 Flutter SDK

android - 动态更改 fragment 选项卡主机内的 fragment ?

java - 当一个 @Around 建议无法继续时,建议优先级问题

android - 指南针在某些设备上不工作

java - 为什么当需要 java List 时,Buffer 却没有发生 JavaConversions._ ?

android - TabWidget不会显示,即使它在ADT编辑器中显示

android - Fragment第二次不显示TabHost的内容