我创建了一个 TabHost 并使用选项卡分配了 4 个活动意图,这些似乎工作得很好。我唯一的问题是活动内容未显示在我的 tabhost 视图的框架布局 #tabcontent 中。
我已经按照官方参考并在互联网上扫描了解决方案,但我看不出问题出在哪里。
Log.v("Activity", "Reports") 记录在 ant 中,因此它确实执行了活动。因此,我猜测是我的 ReportsActivity 中的 setContentView() 导致了问题。但我是新手,所以我真的说不出来。(没有生成的错误)
这是我的tabhost
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/tabhost"
android:background="#FFFFFF">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5sp"
android:layout_weight="1" />
</LinearLayout>
</TabHost>
这就是我在 TabActivity 中添加标签的方式
// Glob
Intent intent;
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Resources res = getResources();
// Reports tab
intent = new Intent().setClass(this, ReportsActivity.class);
spec = tabHost.newTabSpec("reports")
.setIndicator(
res.getText(R.string.reports),
res.getDrawable(R.drawable.reports))
.setContent(intent);
tabHost.addTab(spec);
这是我的内容活动(R.layout.reports = linearlayout with a textview)
public class ReportsActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reports);
Log.v("Activity", "Reports");
}
}