如果应用程序在应用程序中有主题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)
答案 0 :(得分:11)
您无法进行教学步骤'如果活动没有ActionBar,则指向一个菜单项(这显然是为什么......你还没有菜单项)。
如果您想将圆圈置于活动/片段内的视图中心,这应该适合您。
ShowcaseView.Builder res = new ShowcaseView.Builder(activity, true)
.setTarget(target)
.setContentTitle("title")
.setContentText("content");
目标是:
Target target = new ViewTarget(view_id, activity)
答案 1 :(得分:10)
我通过这段代码解决了我的类似问题(片段中):
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();
答案 2 :(得分:2)
如果你想在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);
}
};
答案 3 :(得分:0)
我有解决办法..... 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库。我在这里由两个不同的库编写。一个是
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();
仅此而已。快乐的编码...