如何使用 Fragment 实现全屏?
我正在编写的应用程序中使用兼容性库,所以我可以提供对 Android 2.1 的支持并使用 Fragments
。我的应用程序中有一个 Activity
负责显示我的片段。一个片段播放视频,所以我希望这个特定的片段占据整个屏幕。到目前为止,我已经尝试了以下方法,但这并没有实现我的目标:
getActionbar().hide();
抛出“没有这样的方法”错误,我猜测是因为我在 Pre-Honeycomb 设备上运行该应用程序。
我还尝试过调用:
getActivity().requestWindowFeature(Window.FEATURE_NO_TITLE);
,它会因以下内容而崩溃:
android.util.AndroidRuntimeException: requestFeature() must be called before adding content
我猜测这是在加载活动而不是片段时调用的。
I'm using the compatibility library in an app I'm writing, so I can provide support back to Android 2.1 and use Fragments
. I've got one Activity
in my application that is in charge of displaying my Fragments. One Fragment plays video, so I want this particular Fragment to take up the entire screen. I have tried the following so far, which has not worked in achieving my goal:
getActionbar().hide();
Throws a No Such Method error, I'm guessing because I'm running the app on a Pre-Honeycomb device.
I have also tried calling:
getActivity().requestWindowFeature(Window.FEATURE_NO_TITLE);
which crashes with the following:
android.util.AndroidRuntimeException: requestFeature() must be called before adding content
I'm guessing that this is meant to be called when loading an Activity, not a Fragment.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个错误本身就说明了问题。您必须在调用 setContentView 之前放置 requestfeature 行。
您可以像这样指定清单并查看它是否适合您吗?
我相信也有全屏主题。
The error speaks for itself. You gotta put the requestfeature line before calling setContentView.
Can you specify manifest like this and see if it is working for you?
I believe there is theme for fullscreen too.