Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Action Bar Sherlock action item view

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?

like image 785
sealskej Avatar asked Nov 05 '22 11:11

sealskej


1 Answers

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

like image 164
Manfred Moser Avatar answered Nov 11 '22 08:11

Manfred Moser