问题描述
我计划在我的应用程序中使用快速操作 UI 模式.Android 快速操作 UI 模式.快速操作窗口需要一个枢轴视图来坚持.
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 属性来实现这一点,然后您将能够获得您想要的透视图.代码应该是这样的
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;
}
这篇关于Android:获取对菜单项的视图引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!