如何查看隐藏菜单?

时间:2016-06-09 06:54:32

标签: android menu toolbar

我必须在我的Android应用程序中实现弹出工具提示,所以我需要为我的屏幕元素获取有趣的View对象。

但是我从工具栏菜单中查看了一些问题。我需要获取一个对象View菜单项,如下所示。

enter image description here

有人知道如何获取此UI元素的对象View?感谢。

1 个答案:

答案 0 :(得分:1)

我发现下一个不是很好,但是实现它的工作方式。

int count = mToolbar.getChildCount();
        for (int i = 0; i < count; i++) {
            View view = mToolbar.getChildAt(i);
            Log.e("View type ", mToolbar.getChildAt(i).getClass().getSimpleName());
            if (view instanceof ActionMenuView) {
                int childCount = ((ActionMenuView) view).getChildCount();
                for (int y = 0; y < childCount; y++) {
                    View overFlowMenuButton = ((ViewGroup) view).getChildAt(y);
                    Log.e("ActionMenuView type", ((ViewGroup) view).getChildAt(y).getClass().getSimpleName());
                    if (overFlowMenuButton.getClass().getSimpleName().equalsIgnoreCase("OverflowMenuButton")) {

                        Log.e("Need view ", overFlowMenuButton.getClass().getSimpleName());
                    }
                }
            }
        }