没有 ActionBar,ShowcaseView 无法工作

ShowcaseView is not working without ActionBar

如果应用程序有主题 Theme.AppCompat.Light.NoActionBar 并在应用程序中使用 android.support.v7.widget.Toolbar,是否有任何方法可以使用 ShowcaseView。我在执行应用程序时低于堆栈跟踪。请建议...

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

如果 activity 没有 ActionBar,您将无法使 'tutorial step' 指向菜单项(很明显,为什么...您没有菜单项)。

如果您想在 activity/fragment 内的视图中将圆圈居中,这应该适合您。

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

目标是:

Target target = new ViewTarget(view_id, activity)

我通过这段代码(片段)解决了我的类似问题:

        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();

如果你想在 overflowMenu 上显示提示,那么你可以尝试使用 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);
    }
};

Showcase 似乎不能很好地与 Android Studio 热部署功能配合使用(可能是因为 reflation 使用)。

当我清理项目并重新启动(在使用正确的展示构建器之后)时,它起作用了。

我找到了解决方案..... Appcompat 工具代码

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

然后使用你喜欢的 targetview library.I 在这里写两个不同的 library.One 是

 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();

那是all.Happy编码……