[url]http://developer.android.com/guide/topics/ui/actionbar.html#ActionProvider[/url]
[url]http://stackoverflow.com/questions/19439106/cant-display-sub-menu-for-custom-actionprovider[/url]
Unfortunately, onPrepareSubMenu() is only called when onCreateActionView() returns null. Your solution (attaching a PopupMenu to the ImageView) will work, but since your ImageView is displaying an icon, you might consider just setting the icon in the menu XML and getting rid of the ImageView:
[url]http://stackoverflow.com/questions/19439106/cant-display-sub-menu-for-custom-actionprovider[/url]
Unfortunately, onPrepareSubMenu() is only called when onCreateActionView() returns null. Your solution (attaching a PopupMenu to the ImageView) will work, but since your ImageView is displaying an icon, you might consider just setting the icon in the menu XML and getting rid of the ImageView:
@Override
public View onCreateActionView(){
return null;
}
本文介绍了在Android开发中如何正确使用ActionProvider显示子菜单的方法。文章指出onPrepareSubMenu仅在onCreateActionView返回null时被调用,并提供了一个替代方案:通过在菜单XML中设置图标并移除ImageView来实现。
752

被折叠的 条评论
为什么被折叠?



