ActionBar的溢出菜单打开

ActionBar的溢出菜单打开

本文介绍了ActionBar的溢出菜单打开/关闭监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,当用户打开/关闭动作条的溢出菜单(三个点),好歹像这样听:

I want to listen when user opens/closes the overflow menu (three dots) of ActionBar, someway like this:

void onOverflowMenu(boolean expanded) {
}

要处理打开的情况下,我已经试过在prepareOptionsMenu(),但它还是触发时,动作条构造时 invalidateOptionsMenu( )被调用。这不是我想要的。

To handle open cases, I've tried onPrepareOptionsMenu(), but it's triggered when ActionBar is constructed or when invalidateOptionsMenu() is called. This is not what I want.

我能够检测到溢出菜单关闭,如果用户选择 onMenuItemSelected菜单项()。但我也想,如果用户通过点击它之外,通过pressing返回键关闭溢出菜单,和所有其他情况下,检测到它。

I was able to detect overflow menu is closed if user selects a menu item in onMenuItemSelected(). But I also want to detect it if user closes overflow menu by tapping outside of it, by pressing back key, and all other cases.

有没有办法来实现呢?

推荐答案

要赶在活动开行动

@Override
public boolean onMenuOpened(int featureId, Menu menu) {
    ...
    return super.onMenuOpened(featureId, menu);
}

要赶上封闭的行动,也如果菜单视图外部用户触摸:

To catch closed action, also if user touch outside of Menu view:

@Override
public void onPanelClosed(int featureId, Menu menu) {
    ...
}

这篇关于ActionBar的溢出菜单打开/关闭监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 05:58