Action Bar Sherlock action item view

六月ゝ 毕业季﹏ 提交于 2020-01-02 04:48:35

问题


I am trying to show quick action after click on action bar item, so I need to get a parent view to to know where should be quick action shown.

Here is my code:

@Override 
public boolean onCreateOptionsMenu(final Menu menu) { 
   prepareQuickActions();

   MenuItem menuItem = menu.add("Text"); 
   menuItem.setIcon(R.drawable.ic_action_dialog_map) 
           .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

   menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() { 
       @Override 
       public boolean onMenuItemClick(final MenuItem item) { 
           quickAction.show(item.getActionView()); 
           return true; 
       } 
   }); 
}

Problem is that item.getActionView() returns null. Where could be a problem? Bug in a library?


回答1:


By default action view of a MenuItem is null because it is just sort of an alternative that you can use to customize. As far as I know there is no way to get to the view of the MenuItem. A workaround I know would be to set the action view first to what you want it to look like (and you can style it any way you like) and then it wont return null ...

Also see Different look/style for specific menu item on ActionBar




回答2:


Could be that your menu.xml is not correct. Check your path for android:actionViewClass:



来源:https://stackoverflow.com/questions/7965261/action-bar-sherlock-action-item-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!