我有一个菜单项。我想为其展示工具提示。所以我将ImageButton设置为ActionView,但是没有调用setOnClickListener。
val menuItem = menu?.getItem(0)
info { "Menu item not null" }
val addView = menuItem?.actionView as ImageButton
// just adding some padding to look better
val density = activity.getResources().getDisplayMetrics().density
val padding = (5 * density).toInt()
addView.setPadding(padding, padding, padding, padding)
addView.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_add_white_24dp, null))
val toolTip = ToolTip().setDescription(activity.getString(R.string.coach_add_dependant)).setGravity(Gravity.LEFT or Gravity.BOTTOM)
info { "Menu item not null1" }
val addDepMenu = TourGuide.init(activity)
.with(TourGuide.Technique.Click)
.motionType(TourGuide.MotionType.ClickOnly)
.setPointer(Pointer())
.setToolTip(toolTip)
.setOverlay(Overlay())
.playOn(addView)
info { "Menu item not null2" }
addView.setOnClickListener {
info { "Menu item not null3" }
info { "Add view clicked" }
addDepMenu.cleanUp()
}
菜单文件:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/addUserMenu"
android:title="Add User"
app:showAsAction="ifRoom"
app:actionViewClass="android.widget.ImageButton"/>
</menu>
有人可以帮我这个吗?