简体   繁体   English

没有调用android actionbar oncreateoptionsmenu

[英]android actionbar oncreateoptionsmenu not called

in my app I can see the actionbar, but I can't see the setting items, because it never call onCreateOptionsMenu. 在我的应用程序中,我可以看到操作栏,但我看不到设置项,因为它从不调用onCreateOptionsMenu。

The app if for target sdk 16, it's composed by a tab and each tab is a fragment. 应用程序如果是目标sdk 16,它由一个选项卡组成,每个选项卡都是一个片段。 On the Fragment class, during the onCreate() I'm calling setHasOptionsMenu(true). 在Fragment类中,在onCreate()期间我调用setHasOptionsMenu(true)。 The theme is Theme.Holo.Light. 主题是Theme.Holo.Light。 If I run the app on the emulator (Android 4.0) and I press the hardware menu item, it calls the method, but it shows me the menu like the Android 2.3 menu, not in the actionbar!! 如果我在模拟器(Android 4.0)上运行应用程序并按下硬件菜单项,它会调用方法,但它会显示菜单,如Android 2.3菜单,而不是在操作栏中!

I don't think the problem is on the sdk version, because the actionbar is visible! 我不认为问题出在sdk版本上,因为操作栏是可见的! Any idea? 任何的想法? what I could check to find the error? 我可以检查找到错误?

Thanks a lot for every help! 非常感谢每一个帮助! My best regards Manuela 我最好的问候曼努埃拉

i got the same issue and solved by this way 我得到了同样的问题并通过这种方式解决了

manifest.xml 的manifest.xml

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar" >

remove android:theme="@android:style/Theme.NoTitleBar" 删除android:theme =“@ android:style / Theme.NoTitleBar”

that's the normal behaviour. 这是正常的行为。 The system adapts itself to the hardware it's running on. 系统适应其运行的硬件。

If the device does not have a hardware button, it shows as a drop-down from the action bar. 如果设备没有硬件按钮,则会显示为操作栏中的下拉列表。 If the device does have a hardware button, it shows as a rise-up from near the menu button. 如果设备有硬件按钮,它会从菜单按钮附近显示为上升。

edit 编辑

If the menu is on the action bar, it's only created once (because the menus stays on the screen, does not go away like on hardware key phones), so there's another callback, I reckon it's onPrepareOptionsMenu or something similar, that one is called before the menu is shows on the screen. 如果菜单在操作栏上,它只创建一次(因为菜单停留在屏幕上,不会像硬件键手机那样消失),所以还有另一个回调,我认为它是onPrepareOptionsMenu或类似的东西,一个叫做在菜单显示在屏幕上之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM