2015-06-24 37 views
3

如果应用程序有一个主题Theme.AppCompat.Light.NoActionBar和在应用程序中使用android.support.v7.widget.Toolbar有什么方法可以使用ShowcaseView。在执行应用程序时,我得到下面的堆栈跟踪。请建议...ShowcaseView不工作没有ActionBar

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) 

回答

11

你将不能够做一个“教程一步”指着一个菜单项目,如果该活动还没有动作条(这是显而易见的,为什么......你没有菜单项) 。

如果您想将圆圈置于活动/片段的视图中,这应该适合您。

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

其中目标是:

Target target = new ViewTarget(view_id, activity) 
+0

使用你的代码后,我得到这个错误'java.lang.IllegalArgumentException:宽度和高度必须> 0' – kosala

+0

这似乎是一个知道的问题,请看这里http://stackoverflow.com/questions/25456289/showcaseview -width和 - 高度必须待0。请注意,您的布料已完全装入。您可能需要添加一个goblal布局侦听器才能在加载布局后启动教程。 –

8

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

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

谢谢!这也适用于我。 – chabislav

1

,如果你想显示在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); 
    } 
}; 
0

它看起来像Showcase在Android Studio热部署功能方面表现不佳(可能是因为使用了refill)。

当我清理项目,并重新启动(使用正确的展示生成器后),它工作。