碎片未接收菜单回调 [英] Fragment not receiving menu callbacks

查看:124
本文介绍了碎片未接收菜单回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个扩展片段键,通话 setHasOptionsMenu 参加菜单中的片段类。此类还实现了 onCreateOptionsMenu 在prepareOptionsMenu onOptionsItemSelected

I have a fragment class that extends Fragment and calls setHasOptionsMenu to participate in the menu. This class also implements onCreateOptionsMenu, onPrepareOptionsMenu and onOptionsItemSelected.

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);
        ....
}

我动态加载使用该片段的 FragmentTransaction 在我的活动(扩展 FragmentActivity )。

I'm dynamically loading this fragment using a FragmentTransaction in my Activity (that extends FragmentActivity).

但是没有一个菜单回调( onCreateOptionsMenu 在prepareOptionsMenu 的onOptionsItemSelected )被称为(我已经调试,在这些方法的一些断点),菜单没有显示。

However none of the menu callbacks (onCreateOptionsMenu, onPrepareOptionsMenu and onOptionsItemSelected) are being called (I've debugged with some breakpoints in those methods) and the menu isn't shown.

我缺少的东西?我是否需要添加的东西在我的活动?

Am I missing something? Do I need to add something in my Activity?

我使用的是Android的兼容性,与L11 SDK和测试在Xoom的编制。

I'm using the Android Compatibility Library, compiling with L11 SDK and testing in a Xoom.

修改:我已经找到了问题。我AndroidManifest的目标是L11,这似乎隐藏回调菜单按钮和prevent被调用。但是,如果我从清单中删除这一点,我失去了一些其他的功能,我需要(例如,在列表中的激活状态)。有谁知道如何不删除解决这个问题(选择菜单按钮) targetSdkVersion = 11 从清单?

EDIT: I've found the problem. My AndroidManifest is targeting L11, this seems to hide the menu button and prevent from the callbacks being called. However if I remove this from the manifest I loose some other features I need (for example the activated state in lists). Does anyone know how to solve this issue (enable the menu button) without removing the targetSdkVersion=11 from the Manifest?

推荐答案

我已经找到了问题。瞄准SDK 11 AndroidManifest,这似乎隐藏回调菜单按钮和prevent被调用。我认为这打破了菜单按钮,似乎在安卓3.0的动作栏被替换的兼容性

I've found the problem. The AndroidManifest is targeting SDK 11, this seems to hide the menu button and prevent from the callbacks being called. I assume that this breaks the compatibility of the menu button that seems to be replaced by the action bar in Android 3.0

这篇关于碎片未接收菜单回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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