我有一个标签栏,我想要添加到多个活动。我有一个TabController.java
它看起来像这样标签栏不显示在活动
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class TabController extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabcontroller);
TabHost tabHost = getTabHost();
Intent intent;
intent = new Intent().setClass(this, Help.class);
TabSpec specHelp = tabHost.newTabSpec("Help").setIndicator("Help")
.setContent(intent);
intent = new Intent().setClass(this, Services.class);
TabSpec specServices = tabHost.newTabSpec("Services").setIndicator("Services")
.setContent(intent);
intent = new Intent().setClass(this, Inbox.class);
TabSpec specInbox = tabHost.newTabSpec("Inbox").setIndicator("Inbox")
.setContent(intent);
intent = new Intent().setClass(this, About.class);
TabSpec specAbout = tabHost.newTabSpec("About").setIndicator("About")
.setContent(intent);
intent = new Intent().setClass(this, More.class);
TabSpec specMore = tabHost.newTabSpec("More").setIndicator("More")
.setContent(intent);
tabHost.addTab(specHelp);
tabHost.addTab(specServices);
tabHost.addTab(specInbox);
tabHost.addTab(specAbout);
tabHost.addTab(specMore);
}
和tabcontroller.xml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TabHost android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/tabhost" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_alignParentBottom = "true"
android:layout_height="wrap_content" />
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</FrameLayout>
</RelativeLayout>
</TabHost>
</merge>
我想与做的是要为布局添加到多个活动。当我尝试添加布局时,我使用<include layout="@layout/tabcontroller"/>
。当我运行项目时,我的选项卡栏不出现在屏幕上。
如何将此标签栏添加到我的活动中? PS。 TabController.java
是不是我的主要活动
我的HomeScreen是我的主页,没有标签栏,所以我有它扩展活动。如果我使'TabController'成为根活动,我怎么能让我的'HomeScreen'首先显示并且不显示标签栏? – BigT 2012-07-25 16:02:10
所以我使用片段,并在我的应用程序,我甚至没有扩展TabActivity类。我编辑了我以前的评论,以便您可以检查 – Android2390 2012-07-25 16:06:12
该方法是否进入我需要标签栏的每个活动? – BigT 2012-07-25 16:33:50