ShowcaseView is not working without ActionBar

4k views Asked by At

Is there any way to use ShowcaseView if the application has a theme Theme.AppCompat.Light.NoActionBar and using android.support.v7.widget.Toolbar in the application. I am getting below stack trace while executing the app. Please suggest...

java.lang.RuntimeException: insertShowcaseViewWithType cannot be used when the theme has no ActionBar
        at com.github.amlcurran.showcaseview.targets.AppCompatReflector.getHomeButton(AppCompatReflector.java:32)
        at com.github.amlcurran.showcaseview.targets.AppCompatReflector.getActionBarView(AppCompatReflector.java:20)
        at com.github.amlcurran.showcaseview.targets.ActionViewTarget.setUp(ActionViewTarget.java:22)
        at com.github.amlcurran.showcaseview.targets.ActionViewTarget.getPoint(ActionViewTarget.java:29)
        at com.github.amlcurran.showcaseview.ShowcaseView$1.run(ShowcaseView.java:149)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5312)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
5

There are 5 answers

2
Juan Aguilar Guisado On BEST ANSWER

You won't be able to make a 'tutorial step' pointing to a menu item if the activity has not ActionBar (it's obvious why... you haven't menu items).

If you want to center the circle in a view inside your activity/fragment, this should work for you.

ShowcaseView.Builder res = new ShowcaseView.Builder(activity, true)
                .setTarget(target)
                .setContentTitle("title")
                .setContentText("content");

Where target is:

Target target = new ViewTarget(view_id, activity)
0
Shahriar Nasim Nafi On

I get a solution..... Code for Appcompat toolber

toolbar = (Toolbar) findViewById(R.id.department_name);
    toolbar.setTitle(R.string.catagory_one);
    toolbar.setSubtitle(getText(R.string.lwebsite));
    toolbar.inflateMenu(R.menu.all_articles);// add this line catching menu items
    setSupportActionBar(toolbar);

Then use your preferred targetview library.I write here this by two different library.One is

 new MaterialTapTargetPrompt.Builder(CatagoryOne_HOME.this)//library link:https://github.com/sjwall/MaterialTapTargetPrompt
            .setTarget(R.id.sync)//this is yours
            .setPrimaryText("Send your first email")
            .setSecondaryText("Tap the envelope to start composing your first email")
            .show();

    ViewTarget target = new ViewTarget(toolbar.findViewById(R.id.sync));//this is yours
    new ShowcaseView.Builder(this)
            .setContentTitle("Its My Navigation Drawer")
            .setContentText("Click here and you will get options to navigate to other sections.")
            .useDecorViewAsParent() 
            .setTarget(target)
            .build();

That's all.Happy coding......

0
Saurabh Mishra On

if you want to show hint at overflowMenu then you can try setting the following target using ShowCaseView#setTarget(Target t):

Target = new Target() {
    @Override
    public Point getPoint() {
        int[] location = new int[2];
        toolBar.getLocationInWindow(location);
        int x = location[0] + toolBar.getWidth() - toolBar.getHeight() / 2;
        int y = location[1] + toolBar.getHeight() / 2;
        return new Point(x, y);
    }
};
0
Eli On

It Looks like Showcase does not play well with the Android Studio hot deploy feature (maybe because of the reflation use).

When I cleaned the project, and restarted (after using the correct showcase builder), it worked.

0
Iman Marashi On

I solve my similar problem by this code (in fragment):

        new ShowcaseView.Builder(getActivity())
    .setTarget( new ViewTarget( ((View) parentView.findViewById(R.id.link_to_register)) ) )
    .setContentTitle("ShowcaseView")
    .setContentText("This is highlighting the Home button")
    .hideOnTouchOutside()
    .build();