gpt4 book ai didi

android - 将 ShowCaseView 与 ActionBarCompat/ActionBarSherlock Android 结合使用

转载 作者:太空宇宙 更新时间:2023-11-03 13:25:51 25 4
gpt4 key购买 nike

我正在使用来自 hereShowcaseView 库在我的安卓应用程序中。我想将 ShowcaseViewActionbar Compat 一起使用。但我不知道如何使用它?我尝试了以下代码,但它抛出 NullPointerexception。请帮我解决这个问题。

谢谢。

代码:

public class Activity1 extends ActionBarActivity implements
OnShowcaseEventListener {

ShowcaseView sv;
ShowcaseView.ConfigOptions co;

@Override
protected void onCreate(Bundle savedInstanceState) {
try {
super.onCreate(savedInstanceState);
setContentView(R.layout.screen1);
co = new ShowcaseView.ConfigOptions();
co.hideOnClickOutside = false;
co.block = false;
}catch (Exception ex) {
ex.printStackTrace();
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);

ActionViewTarget target = new ActionViewTarget(this,
ActionViewTarget.Type.OVERFLOW);
sv = ShowcaseView.insertShowcaseView(target, this, "Edit",
"Click here to edit image.", co);
}
}

错误日志:

11-29 17:12:19.792: E/AndroidRuntime(20991): FATAL EXCEPTION: main
11-29 17:12:19.792: E/AndroidRuntime(20991): java.lang.NullPointerException
11-29 17:12:19.792: E/AndroidRuntime(20991): at com.espian.showcaseview.targets.ViewTarget.getPoint(ViewTarget.java:22)
11-29 17:12:19.792: E/AndroidRuntime(20991): at com.espian.showcaseview.targets.ActionViewTarget.getPoint(ActionViewTarget.java:52)
11-29 17:12:19.792: E/AndroidRuntime(20991): at com.espian.showcaseview.ShowcaseView$3.run(ShowcaseView.java:240)
11-29 17:12:19.792: E/AndroidRuntime(20991): at android.os.Handler.handleCallback(Handler.java:725)
11-29 17:12:19.792: E/AndroidRuntime(20991): at android.os.Handler.dispatchMessage(Handler.java:92)
11-29 17:12:19.792: E/AndroidRuntime(20991): at android.os.Looper.loop(Looper.java:137)
11-29 17:12:19.792: E/AndroidRuntime(20991): at android.app.ActivityThread.main(ActivityThread.java:5283)
11-29 17:12:19.792: E/AndroidRuntime(20991): at java.lang.reflect.Method.invokeNative(Native Method)
11-29 17:12:19.792: E/AndroidRuntime(20991): at java.lang.reflect.Method.invoke(Method.java:511)
11-29 17:12:19.792: E/AndroidRuntime(20991): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
11-29 17:12:19.792: E/AndroidRuntime(20991): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
11-29 17:12:19.792: E/AndroidRuntime(20991): at dalvik.system.NativeStart.main(Native Method)

最佳答案

我解决了那个问题。将 OnCreateOptionsMenu() 的代码替换为以下代码。

代码:

@Override
public boolean onCreateOptionsMenu(Menu menu) {

MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);

sv = ShowcaseView.insertShowcaseViewWithType(ShowcaseView.ITEM_ACTION_ITEM,
R.id.action_edit, FaceFrameActivity_dual.this,"Edit",
"Click here to edit image.", co);
}

关于android - 将 ShowCaseView 与 ActionBarCompat/ActionBarSherlock Android 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20284955/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com