如何在此功能中删除图像所选部分的颜色,非常感谢您的帮助,第一个代码是onnavigationitemselected,第二个是我要删除所选颜色的颜色< / p>
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_mapa)
{
// Handle the home action
MapFragment mapFragment = new MapFragment();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, mapFragment);
fragmentTransaction.commit();
} else if (id == R.id.nav_anuncios)
{
AnunciosFragment anunciosFragment = new AnunciosFragment();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, anunciosFragment);
fragmentTransaction.commit();
} else if (id == R.id.nav_adopciones)
{
AdopcionesFragment adopcionesFragment = new AdopcionesFragment();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, adopcionesFragment);
fragmentTransaction.commit();
} else if (id == R.id.nav_protectoras)
{
ProtectorasFragment protectorasFragment = new ProtectorasFragment();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, protectorasFragment);
fragmentTransaction.commit();
} else if (id == R.id.nav_ajustes)
{
Toast.makeText(this, "Ajustes clicked", Toast.LENGTH_SHORT).show();
} else if (id == R.id.nav_contacto)
{
Toast.makeText(this, "Contacto Clicked", Toast.LENGTH_SHORT).show();
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
Perfil功能:
public void Perfil(View view)
{
HomeFragment homeFragment = new HomeFragment();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, homeFragment);
fragmentTransaction.commit();
//per tancar NAV al seleccionar
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
}
答案 0 :(得分:3)
public boolean onNavigationItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.nav_camera:
break;
case R.id.nav_gallery:
break;
}
mDrawerLayout.closeDrawer(GravityCompat.START);
return false;
}
return false表示未经检查的状态。
或者你可以这样做:
drawer.getMenu().findItem(R.id.nav_camera).setChecked(false);
答案 1 :(得分:0)
您需要检查false取消选择菜单项
navigationView.getMenu().getItem(3).setChecked(false);
getItem(3)
表示您需要传递菜单项的索引