onCreateOptionsMenu不会被调用onCreateOptionsMenu

2023-09-04 08:44:20 作者:無話可說

我有一些麻烦的选项菜单中的Andr​​oid工作。我以前构建应用程序,他们都工作得很好,但现在的菜单只是没有弹出。

I am having some trouble getting an options menu working in Android. I build apps before, and they all worked fine, but now the menu just doesn't pop up.

在code:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    getMenuInflater().inflate(R.menu.activity_video, menu);
    return true;
}

整个方法从来没有所谓的(通过设置一个断点检查)。该活动是超级简单,它只是有一个 VideoView 在里面,用 OnTouchListener 设置。

the whole method is never even called (checked by setting a breakpoint). The activity is super-simple, it just has a VideoView in it, with an OnTouchListener set.

我使用的是Android 4.0.4上的三星Galaxy 10.1,API级别15,minSDK 15.我失去了一些东西?

I am using Android 4.0.4 on a Samsung Galaxy 10.1, API level 15, minSDK 15. Am I missing something?

推荐答案

如果您测试的手机有onCreateOptionsMenu wont't算得上下手为主题的菜单按钮:

If the phone you test on has a menu button onCreateOptionsMenu wont't be called on start with the theme:

安卓主题=@安卓风格/ Theme.Black.NoTitleBar

但是,当你点击菜单按钮 onCreateOptionsMenu 将被调用。我不知道在手机上发生的事情没有硬件按钮...

But when you click the menu button the onCreateOptionsMenu will be called. I don't know what happens on phones without hardware buttons...