ShowcaseView在没有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$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)

如果活动没有ActionBar,您将无法进行指向菜单项的"教程步骤"(原因很明显……您没有菜单项)。

如果你想在你的活动/片段内的视图中将圆圈居中,这应该对你有用。

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

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

我得到了一个解决方案。。。。。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);

然后使用您喜欢的targetview库。这是我在两个不同的图书馆写的。一种是

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

仅此而已。快乐编码。。。。。。

相关内容

最新更新