带有片段的ActionBar(支持)(支持) [英] ActionBar (Support) with Fragment (support)

查看:94
本文介绍了带有片段的ActionBar(支持)(支持)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还需要在我的一个针对Gingerbread的android应用程序中结合使用操作栏和片段.因此,我使用了v7支持库中的操作栏和v4支持库中的片段,并使用FragmentActivity扩展了我的类.

I need to use a combination of action bar and fragments in one of my android applications that targets Gingerbread too. So I have used the action bar from the v7 support library and fragments from the v4 support library and extend my class with FragmentActivity.

输入行时出现错误

actionbar = getSupportActionBar();

错误指出,对于myFragmentClass 类型(我的类名),未定义 getSupportActionBar().该代码无需支持库即可完美运行.我的问题有解决方案吗?

The error states that getSupportActionBar() is undefined for the type myFragmentClass (my class name). The code works perfectly without the support library. Is there a solution to my problem?

谢谢!

推荐答案

您必须扩展ActionBarActivity而不是FragmentActivity才能使Actionbar带有片段.

You must extend ActionBarActivity instead of FragmentActivity to have Actionbar with fragments.

如果您使用的是v7 appcompat库,则您的活动应扩展ActionBarActivity,它是FragmentActivity的子类(有关更多信息,请参阅添加操作栏).

If you're using the v7 appcompat library, your activity should instead extend ActionBarActivity, which is a subclass of FragmentActivity (for more information, read Adding the Action Bar).

您可以在下面的页面中找到更多信息.上一行来自下面的页面(最后一节). http://developer.android.com/training/basics/fragments/creating.html

You can find more info at the page given below.The above line is taken from the page below(Last para). http://developer.android.com/training/basics/fragments/creating.html

编辑-这不是错误.它只是缺乏知识.有时基本不清楚.我目前正在android网站上学习,这就是我如何给您答案.

Edit- This is not a bug. Its just lack of knowledge. Sometimes basic are not clear. I am currently learning, that too from the android website, and that's how I got to give you the answer.

这篇关于带有片段的ActionBar(支持)(支持)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆