安卓:获取视图引用到菜单项 [英] Android : Get view Reference to a Menu Item

查看:134
本文介绍了安卓:获取视图引用到菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算使用快速行动UI模式在我的应用程序。 Android的快速操作的用户界面模式。快速操作窗口需要一个支点,以坚持。

I plan to use quick actions UI pattern in my application. Android Quick Actions UI Pattern . The quick action window needs a pivot view to stick to.

    quickAction.show(View pivotView);

我打算用快速行动的菜单项目,我可以访问被点击的项目。 但问题是,我需要从菜单项中引用视图,这样我可以把它传递给迅速采取行动。

I intend to use quick action for the menu Item, I can get access to the item that is clicked. But the problem is i need to reference a view from the menu item so that i can pass it to the quick action.

我怎样才能参考所选的菜单项的景色。

How can i get reference to a view in the menuItem that is selected.

推荐答案

您可以通过提供您的菜单项,在XML的actionViewClass性能达到这一点,那么你将能够获得枢轴视图u想。在code会是这样

You can achieve this by providing your menu item with an actionViewClass property in xml and then you will be able to get the pivot view u wanted. The code would be something like this

<item
    android:id="@+id/menu_find"
    android:showAsAction="ifRoom"
    android:actionViewClass="android.widget.ImageButton"
    />

在您OnCreateOptionsMenu做到这一点

In your OnCreateOptionsMenu do this

public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.menu_search, menu);
    locButton = (ImageButton) menu.findItem(R.id.menu_find).getActionView();
    locButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            createPopup();
            mQuickAction.show(v);
        }
    });
    return true;
}

这篇关于安卓:获取视图引用到菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆