我试图使用这个库Android-Target-Tooltip,特别是我试图将按钮弹出消息显示在工具栏中,这就是我所做的:
@Override
public boolean onCreateOptionsMenu(final Menu menu)
{
menu.add(Menu.NONE, 0, Menu.NONE, "Info").setIcon(R.drawable.ic_info_outline_black_30dp)
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
Tooltip.make(getApplicationContext(),
new Tooltip.Builder(102)
.anchor(menu.findItem(0).getActionView(), Tooltip.Gravity.BOTTOM)
.closePolicy(new Tooltip.ClosePolicy()
.insidePolicy(true, false)
.outsidePolicy(true, false), 10000)
.text("This is text")
.maxWidth(800)
.withArrow(true)
.withOverlay(true)
.build()
).show();
return false;
}
}).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
return true;
}
但是当我点击它时会抛出 java.lang.UnsupportedOperationException
java.lang.UnsupportedOperationException: Failed to resolve attribute at index 1: TypedValue{t=0x2/d=0x7f010093 a=1236}
at android.content.res.TypedArray.getColor(TypedArray.java:459)
at it.sephiroth.android.library.tooltip.TooltipOverlayDrawable.<init>(TooltipOverlayDrawable.java:54)
at it.sephiroth.android.library.tooltip.TooltipOverlay.init(TooltipOverlay.java:25)
at it.sephiroth.android.library.tooltip.TooltipOverlay.<init>(TooltipOverlay.java:37)
at it.sephiroth.android.library.tooltip.Tooltip$TooltipViewImpl.<init>(Tooltip.java:472)
at it.sephiroth.android.library.tooltip.Tooltip.make(Tooltip.java:71)
at com.android.launcher3.SettingsActivity$1.onMenuItemClick(SettingsActivity.java:83)
at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:167)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:973)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:963)
at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:624)
at android.support.v7.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:150)
at android.view.View.performClick(View.java:5623)
at android.view.View$PerformClick.run(View.java:22433)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6247)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
我做错了什么?