我使用了底部应用栏,问题是当我在菜单中使用 app:actionLayout 为我的菜单使用自定义布局时,单击对这些菜单不起作用,即 setOnMenuItemClickListener for bottomappbar 不起作用。?不使用 actionLayout 时它工作正常。
BottomAppBar bottomAppBar;
bottomAppBar = findViewById(R.id.bar);
bottomAppBar.replaceMenu(R.menu.announcement_menu);
bottomAppBar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_all:
Log.d("Announcement", "All clicked");
break;
case R.id.action_rec:
Log.d("Announcement", "Received clicked");
break;
case R.id.action_sen:
Log.d("Announcement", "Sent clicked");
break;
}
return false;
}
});
和菜单文件
<?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/action_all"
app:actionLayout="@layout/custom_menu_row_all"
android:title="All"
app:showAsAction="always" />
<item
android:id="@+id/action_rec"
app:actionLayout="@layout/custom_menu_row_received"
android:title="Received"
app:showAsAction="always" />
<item
android:id="@+id/action_sen"
app:actionLayout="@layout/custom_menu_row_sent"
android:title="Sent"
app:showAsAction="always" />
</menu>