Search code examples
androidmenu-items

Get view from MenuItem which property "showAsAction" never


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)?


Solution

  • 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.