【问题标题】:onCreateOptionsMenu in SherlockFragment not called未调用 SherlockFragment 中的 onCreateOptionsMenu
【发布时间】:2014-06-17 13:02:38
【问题描述】:

我在带有 ActionBar Navigation Drawer 的 SherlockFragmentActivity 中有一个 SherlockFragment。我想为每个片段显示不同的图标。当我在 android 2.3.6 上运行应用程序时,会调用 onCreateOptionsMenu 方法,但是当我在 android 4+ 中运行应用程序时,不会调用该方法。

谁能帮帮我?

谢谢。

编辑:

This image is first section of an app that has that i want. Menu: dropdown, search collapsible and right sidemenu.

And this is another section of the same app with the same navigation drawer and has different menu items for each fragment.

【问题讨论】:

    标签: android actionbarsherlock oncreateoptionsmenu


    【解决方案1】:

    您使用了哪个主题?在您的清单中,尝试将您的主题更改为 Theme.Black.NoTitleBar。 或全息

    android:theme="@android:style/Theme.Black.NoTitleBar"
    

    选项菜单不适用于以后的版本。 在 API 11 之前,没有操作栏。 ActionBar Sherlock 允许您在 Android 设备上使用操作栏,或者您可以在项目中使用支持库 v7 来使用操作栏。 有 Action 类作为更高版本的 android 版本的标准解决方案。您可以阅读此ActionBar 教程,适用于您的 android 4.0+ 设备。

    【讨论】:

    • 我的主题是 Theme.Serlock.Light。你的答案是错误的,我正在使用 ActionBarSherlock。如果使用您的解决方案会导致 nullpointerexception。
    • Hughan 我需要使用夏洛克主题。如果不导致空指针异常。问题是在 android 2.3.6 上调用了该方法,但在 android 4+ 上没有调用。
    • 如何将菜单项添加到每个片段的 actionbarsherlock?现在明白我了吗?谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-10
    相关资源
    最近更新 更多