Android 如何在工具栏中的每个菜单上实现onclick事件我使用了TapTargetview库
你为什么要用图书馆来做这个?它在Android框架中非常简单。只需用xml创建一个菜单,并用代码将其膨胀即可。 以下是my_toolbar_menu.xml:Android 如何在工具栏中的每个菜单上实现onclick事件我使用了TapTargetview库,android,material-design,Android,Material Design,你为什么要用图书馆来做这个?它在Android框架中非常简单。只需用xml创建一个菜单,并用代码将其膨胀即可。 以下是my_toolbar_menu.xml: final TapTargetSequence sequence=new TapTargetSequence(this) .targets( TapTarget.forToolbarMenuItem(toolbar,R.id.action_search,"S
final TapTargetSequence sequence=new TapTargetSequence(this)
.targets(
TapTarget.forToolbarMenuItem(toolbar,R.id.action_search,"Search","Search here!!!")
.outerCircleColor(R.color.red) // Specify a color for the outer circle
.outerCircleAlpha(0.96f) // Specify the alpha amount for the outer circle
.targetCircleColor(R.color.white) // Specify a color for the target circle
.titleTextSize(24) // Specify the size (in sp) of the title text
.titleTextColor(R.color.white) // Specify the color of the title text
.descriptionTextSize(28) // Specify the size (in sp) of the description text
.descriptionTextColor(R.color.white) // Specify the color of the description text
.textColor(R.color.white) // Specify a color for both the title and description text
.textTypeface(Typeface.SANS_SERIF) // Specify a typeface for the text
.dimColor(R.color.black) // If set, will dim behind the view with 30% opacity of the given color
.drawShadow(true) // Whether to draw a drop shadow or not
.cancelable(false) // Whether tapping outside the outer circle dismisses the view
.tintTarget(true) // Whether to tint the target view's color
.transparentTarget(false) // Specify whether the target is transparent (displays the content underneath)
.targetRadius(40)
.id(1),
TapTarget.forToolbarMenuItem(toolbar,R.id.action_cart,"Cart","Cart here!!!")
.id(2),
TapTarget.forToolbarNavigationIcon(toolbar,"Navigation","Navigation here!!!")
.id(3)
);
sequence.start();
现在处理点击事件,如下所示:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.my_toolbar_menu, menu);
return true;
}
是的,但TapTargetView为我提供了android框架中不存在的UI功能。我没有使用过该功能,但当我重建项目时,它不会影响框架的事件:(…非常感谢Zaid Mirza的回复。。
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.my_toolbar_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.add_menu:
doSomething();
return true;
case R.id.help:
getHelp();
return true;
default:
return super.onOptionsItemSelected(item);
}
}