【发布时间】:2013-09-09 17:44:03
【问题描述】:
我正在开发一个应用程序,最低 sdk 级别为 7,这就是为什么我使用支持库和 ActionBarActivity 来拥有一个适当的 ActionBar,而且我的页面布局在活动底部包含四个选项卡,因为我已经扩展 ActionBarActivity,我无法扩展 TabActivity。 问题是我写的时候
public class HomePageActivity extends ActionBarActivity {
private TabHost mTabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_homepage);
mTabHost = (TabHost) findViewById(android.R.id.tabhost);
mTabHost.setup();
TabHost.TabSpec tab1 = mTabHost.newTabSpec("TAB1");
tab1.setIndicator("TAB 1");
Intent popularContentIntent = new Intent().setClass(this, GuideActivity.class);
tab1.setContent(popularContentIntent);
mTabHost.addTab(tab1);
当我尝试将选项卡添加到选项卡主机时,我收到错误“您是否忘记调用 'public void setup(LocalActivityManager activityGroup)?'”。 如果我尝试在 tab.setContent(..) 中设置视图的 ID,如 tab.setContent(R.id.tab1) 并在 xml 中有一个 ID 为 tab1 的视图,我会收到该视图的错误找不到这样的号码。
我的布局:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@android:id/tabs"
android:layout_alignParentTop="true" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
</Button>
</TabWidget>
</RelativeLayout>
是否有可能以某种方式同时使用选项卡和操作栏进行布局?我做错了什么?还有什么其他选择? 非常感谢!
【问题讨论】:
-
在拨打
addTab(...)之前,您必须先拨打mTabHost.setup()。 -
@Squonk - 这就是我所做的: mTabHost = (TabHost) findViewById(android.R.id.tabhost); mTabHost.setup();
-
抱歉,我略读了您的帖子,直接进入了所报告的错误。
-
除了您在问题中提到的错误之外,您是否在 logcat 中看到任何错误?
-
@Squonk 不,不幸的是:(
标签: android android-actionbar android-tabhost android-tabs android-support-library