Aka*_*tra 1 eclipse android tabactivity android-tabhost android-logcat
我正在学习在android中创建基于Tab的应用程序.在LogCat中,"你必须指定一种创建标签指示器的方法"错误.
继承人的代码......
.java文件......
package com.example.tabdemo;
import android.os.Bundle;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.view.Menu;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
@SuppressWarnings("deprecation")
public class MainActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabhost=getTabHost();
TabHost.TabSpec spec1=tabhost.newTabSpec("Tab 1");
Intent intent1=new Intent(this, Tabone.class);
spec1.setContent(intent1);
// spec1.setIndicator("Tab 1", getResources().getDrawable(R.drawable.face));
spec1.setIndicator("Tab 1");
tabhost.addTab(spec1);
TabHost.TabSpec spec2=tabhost.newTabSpec("Tab 2");
Intent intent2=new Intent(this,Tabtwo.class);
spec2.setContent(intent2);
// spec1.setIndicator("Tab 2", getResources().getDrawable(R.drawable.face));
spec1.setIndicator("Tab 2");
tabhost.addTab(spec2);
tabhost.setCurrentTab(1);
}
}
Run Code Online (Sandbox Code Playgroud)
活动xml文件...
<?xml version="1.0" encoding="utf-8"?>
<TabHost 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">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
</TabHost>
Run Code Online (Sandbox Code Playgroud)
您没有为tab2设置指标
检查你的代码
spec2.setContent(intent2);
// spec1.setIndicator("Tab 2", getResources().getDrawable(R.drawable.face));
spec1.setIndicator("Tab 2");
Run Code Online (Sandbox Code Playgroud)
你覆盖你的tab1指标.
| 归档时间: |
|
| 查看次数: |
3444 次 |
| 最近记录: |