ActionBarActivity与TabHost [英] ActionBarActivity with TabHost
问题描述
我开发一个应用程序,以最小的SDK 7级,这就是为什么我使用支持库和ActionBarActivity有一个正确的动作条,也是我的网页的布局包含对活动的底部有四个选项卡,并作为我已经延长ActionBarActivity,我不能延长TabActivity。 问题是,当我写
I am developing an app, with minimum sdk level 7 and that's why I use support library and ActionBarActivity to have a proper ActionBar, but also the layout of my page contains four tabs on the bottom of the activity, and as i already extend ActionBarActivity, I cannot extend TabActivity. The problem is when I write
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);
我得到的错误难道你忘了叫'公共无效设置(LocalActivityManager的ActivityGroup)?'在我尝试添加标签的tabhost行。 如果我尝试设置在tab.setContent(..)像tab.setContent(R.id.tab1)视图的ID,并在id为TAB1的XML数据的视图,我得到了错误的观点这样的数量不能被发现。
I get the error "Did you forget to call 'public void setup(LocalActivityManager activityGroup)?'" at the line when I trying to add tab to the tabhost. If I try to set the id of the view in the tab.setContent(..) like tab.setContent(R.id.tab1) and have a view in the xml with the id tab1, I get the error that the view with such a number cannot be found.
我的布局:
<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>
是否有可能以某种方式与标签和动作条布置在同一时间?我做错了什么?可能是什么其他的选择吗? 非常感谢!
Is it possible somehow to have layout with tabs and actionbar at the same time? What I do wrong? What could be other alternatives? Thanks a lot!
推荐答案
TabActivity
已被取消precated在API层面13.更新的文档推荐使用 android.support.v4.app.FragmentTabHost
代替。
TabActivity
was deprecated in API level 13. The updated documentation recommends using android.support.v4.app.FragmentTabHost
instead.
这是更好的方法是使用所提供的 ViewPager 样品=https://developer.android.com/reference/android/support/v4 /view/ViewPager.html相对=nofollow>这里。
An even better method would be to use the ViewPager
sample provided here.
这篇关于ActionBarActivity与TabHost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!