0

I use this library to show a Guide Tour. I want to implement the Spotlight into Menu Item which have property showAsAction as never. Below my snippet code :

View view = getActivity().findViewById(R.id.menu_item_refresh);
        new SpotlightView.Builder(getActivity())
                .introAnimationDuration(400)
                .enableRevealAnimation(true)
                .performClick(true)
                .fadeinTextDuration(400)
                .headingTvColor(Color.parseColor("#eb273f"))
                .headingTvSize(32)
                .headingTvText("")
                .subHeadingTvColor(Color.parseColor("#ffffff"))
                .subHeadingTvSize(16)
                .subHeadingTvText("Tap on chart to show detail")
                .maskColor(Color.parseColor("#dc000000"))
                .target(view)
                .lineAnimDuration(400)
                .lineAndArcColor(Color.parseColor("#eb273f"))
                .dismissOnTouch(true)
                .dismissOnBackPress(true)
                .enableDismissAfterShown(true)
                .usageId("")
                .show();

I get this error :

FATAL EXCEPTION: main
                 Process: x.com.d, PID: 15058
                 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.getLocationInWindow(int[])' on a null object reference
                 at com.wooplr.spotlight.target.ViewTarget.getPoint(ViewTarget.java:23)
                 at com.wooplr.spotlight.shape.Circle.getFocusPoint(Circle.java:36)
                 at com.wooplr.spotlight.shape.Circle.<init>(Circle.java:24)
                 at com.wooplr.spotlight.SpotlightView$Builder.build(SpotlightView.java:1082)
                 at com.wooplr.spotlight.SpotlightView$Builder.show(SpotlightView.java:1091)

I see the error happened because the Menu Item is invisible on the main view. I read this related question but I still get same error. Is possible to get that item which is invisible (never as action)?

halfer
  • 19,824
  • 17
  • 99
  • 186
MrX
  • 953
  • 2
  • 16
  • 42

2 Answers2

1

You need to override the following method to access the MenuItem View:

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem menuItem = menu.findItem(R.id.the_one_to_spotlight);
    View view = MenuItemCompat.getActionView(menuItem);

   // Now do whatever you want with the View

    return super.onPrepareOptionsMenu(menu);
}

I assume .target(view) will do the trick in this case.

If that still does not give you the View you need, I would consider changing your showAsAction. Read more useful information about this here: https://stackoverflow.com/a/23080138/5457878

gi097
  • 7,313
  • 3
  • 27
  • 49
  • Your code still have same error, but that is usefull link thank you. Its mean the "hidden" menu item can't be cast into a view? – MrX Jul 23 '18 at 08:26
  • If the view is `GONE` you can't get it. If it's `INVISIBLE` then you should be able to get it: https://stackoverflow.com/a/5756190/5457878 – gi097 Jul 23 '18 at 08:28
0

I found the solution on this reference . JarredRummler answer get the OverflowbMenuButton as a ImageView. Use that method and cast the OverflowMenuButton as View and use it.

MrX
  • 953
  • 2
  • 16
  • 42