It's possible add a notification counter to MenuItem on NavigationView (as
gmail)? I'm developing a dynamic menu and I tried to do that
programatically via MenuItemCompat.setActionView(), but it doesn't work:
private void cargarAvisosMenu() {
// Menu final
Menu menu = this.mNavigationView.getMenu();
// Carga de datos
CentroSelection selection = new CentroSelection();
CentroCursor cur =
selection.query(getApplicationContext().getContentResolver());
// Recorro el cursor de centros
while (cur.moveToNext()) {
boolean avisosTipoA = false;
boolean avisosTipoB = false;
Centro c = Centro.getFromCursor(cur);
if (c.getIsTipoAVisible() &&
c.getComponenteTipoA().getControlesTipoAPendientes() > 0) {
avisosTipoA = true;
}
if (c.getIsTipoBVisible() &&
c.getComponenteTipoB().getControlesTipoBPendientes() > 0){
avisosTipoB = true;
}
if (avisosTipoA || avisosTipoB) {
// Añado la sección y los items.
final SubMenu subMenu = menu.addSubMenu(c.getNombre());
if (avisosTipoA) {
subMenu.add("TipoA").setIcon(R.drawable.ic_tipoA);
}
if (avisosTipoB) {
// subMenu.add("TipoB").setIcon(R.drawable.ic_tipoB);
int itemId = subMenu.add("TipoB").getItemId();
View menuItem = MenuItemCompat.setActionView(subMenu.findItem(itemId),
R.layout.menu_notificaciones).getActionView();
((ImageView)
menuItem.findViewById(R.id.ivMenuNotificaciones)).setBackground(getDrawable(R.drawable.ic_barcode));
((TextView)
menuItem.findViewById(R.id.tvMenuNotificaciones)).setText("TipoB");
((TextView)
menuItem.findViewById(R.id.tvContadorNotificaciones)).setText("100");
}
}
}
}
--
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/android-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-developers/081212f6-0e4c-4303-9286-76307ee25f11%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.