每次按菜单按钮时,两次onMenuOpened/onPanelClosed回调 [英] Double callbacks onMenuOpened/onPanelClosed on each menu button press
问题描述
在我的Android应用中,我想收集有关打开(和关闭)(三个点)操作栏菜单的时间(多长时间)(不选择任何项)的统计信息.对于此任务,我已经覆盖了Activity
中的onMenuOpened
和onPanelClosed
方法.但是,到目前为止,在所有设备(Android 4.4、4.2; Samsung和HTC)上,我都尝试过一次,每次打开和关闭菜单时,这些方法都会触发两次.
这是一个错误吗?有没有其他方法可以监视此菜单的打开和关闭?
In my Android app I want to collect statistics on when (how often) the overflow (three dots) action bar menu is opened and closed (without an item being selected). For this task I have overriden onMenuOpened
and onPanelClosed
methods within an Activity
. However, on all the devices (Android 4.4, 4.2; Samsung and HTC) I've tried this so far these methods are triggered twice, each time the menu is opened and closed.
Is this a bug? Is there another way to monitor this menu opening and closing?
推荐答案
您可以尝试一下...我已经对其进行了测试....它非常完美....
you can try this...i have tested it ....it works perfect....
@Override
public void onActivityCreated(Bundle savedInstanceState) {
Activity activity = getActivity();
activity.getActionBar().addOnMenuVisibilityListener(new OnMenuVisibilityListener() {
@Override
public void onMenuVisibilityChanged(boolean isVisible) {
// TODO Auto-generated method stub
//you can check the isVisible boolean to check
// if the overFlowMenu is visible or not
}
});
这篇关于每次按菜单按钮时,两次onMenuOpened/onPanelClosed回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!