1

I am using showcaseview library to show user guide.In this i have to pass View object to highlight particular view . I am facing problem to find View object of option menu icon (Three dots on top Right Corner). I also tried to this but nothing helpfull.

I also tried as View view=menu.getItem(0).getActionView(); but could not help and always give me exceptionCrash Handler uncaughtException: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.getLocationOnScreen(int[])' on a null object reference

Although i am able to find View object of MenuItem like this View menuItemView1 = findViewById(R.id.menu_edit);

Please let me know anybody have suggestion

amit semwal
  • 345
  • 3
  • 16
  • Use `Activity#findViewById(menu_item_id)`. Options menu view inherit its id from the menu item. This can get tricky though. If the menu is collapsed, this can through NPEs. – ashu Jul 14 '20 at 14:49
  • hi @ashu, I am already able to find menu_item_id but i want Option menu as View so i can Highlight that view for User Guide. – amit semwal Jul 14 '20 at 14:53
  • Read the comment again – ashu Jul 14 '20 at 14:56
  • You are saying like i should try like this `View main_options_menu = findViewById(R.id.menu_item_id);` ? – amit semwal Jul 14 '20 at 15:04
  • Yeah. Which should return a view – ashu Jul 14 '20 at 15:05
  • @ashu when user open the app for the first time then menu would be close and this cause NPEs so how can we get View object? – amit semwal Jul 14 '20 at 15:11
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/217824/discussion-between-amit-semwal-and-ashu). – amit semwal Jul 14 '20 at 15:31
  • Sorry, I am extremely occupied at the moment. I did a quick Google search and [this thread](https://stackoverflow.com/questions/8614293/android-get-view-reference-to-a-menu-item) came up. It seems to have many solutions to the problem you're referring to. – ashu Jul 14 '20 at 16:11

0 Answers0