Jho*_*val 3 java android android-tabhost
我是Android的新手.我正在尝试设置一个简单的TabHost视图.
这是我的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>
Run Code Online (Sandbox Code Playgroud)
这是我的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);
}
}
Run Code Online (Sandbox Code Playgroud)
但该应用程序崩溃与此错误消息(我真的不知道这意味着):

你觉得怎么回事?
改为使用:
<android.support.v4.app.FragmentTabHost
android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
(...)
</android.support.v4.app.FragmentTabHost>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2544 次 |
| 最近记录: |