在手机版本上运行时,FragmentActivity 上不会调用 onCreateOptionsMenu
我创建了一个支持手机和平板电脑版本的应用程序,因此我使用 android-support-v4.jar 库。我的活动扩展了 FragmentActivity 并覆盖了 onCreateOptionsMenu(Menu menu)。这在平板电脑上工作正常, onCreateOptionsMenu 被正确调用,但它在手机上不起作用, onCreateOptionsMenu 永远不会被调用。如何解决这个问题?
注意:我在清单文件上使用
。
I create an app that supports both phone and tablet version so i use the android-support-v4.jar library. My activity extends the FragmentActivity and override the onCreateOptionsMenu(Menu menu). This works fine on tablet, the onCreateOptionsMenu being called correctly but it doesn't work on phone, onCreateOptionsMenu never get called. How to resolve this?
Note: i use <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="12"/>
on Manifest file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该从您的
Fragment
代码中考虑:1) 实现
onCreateOptionsMenu(Menu menu, MenuInflater inflater)
2) 调用
setHasOptionsMenu
3) 并且还实现 < code>onOptionsItemSelected(MenuItem item)
那么你在手机和平板电脑上就可以了。
You should consider from your
Fragment
code:1) Implementing
onCreateOptionsMenu(Menu menu, MenuInflater inflater)
2) Calling
setHasOptionsMenu
3) And also implementing
onOptionsItemSelected(MenuItem item)
Then you will be ok on both the phone and tablet.