我以NavigationView
编程方式添加了项目:
**HERE ADD ITEMS**
Menu rightMenu = mRightDrawerView.getMenu();
for (DataParking dataParking : dataParkingList) {
MenuItem menuItem = rightMenu.add(dataParking.getTimeParking());
}
**HERE ADD CLICK LISTENER**
mRightDrawerView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
// Select menu
menuItem.setChecked(true);
// Closing left_drawer on item click
mDrawerLayout.closeDrawer(mRightDrawerView);
return false;
}
});
导航抽屉中的项目可以正确点击,但选择不是持久的。如果我通过 XML 添加相同的项目一切正常。