I have created drawer with navigation view. I have Navigation item's on which I am calling other activities.
The issue is when I click on navigation item, the other activity launches,and if I come back to main activity and open a drawer the clicked navigation item's title is disappeared only I can see the icon of the item.
code:
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setNavigationIcon(R.drawable.menu_icon);
setSupportActionBar(toolbar);
mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, mDrawer , toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
mDrawer .addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
navigationView.setItemIconTintList(null);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_list) {
startActivity(new Intent(MainActivity.this, LaunchVenueServiceActivity.class));
// Handle the camera action
}
else if (id == R.id.nav_dashboard) {
startActivity(new Intent(MainActivity.this, MainActivity.class));
}
else if (id == R.id.nav_config)
{
startActivity(new Intent(MainActivity.this,LaunchYourServiceStep2.class));
}
else if (id == R.id.nav_chat) {
} else if (id == R.id.nav_notes) {
startActivity(new Intent(MainActivity.this,NotesActivity.class));
} else if (id == R.id.nav_user_guide) {
}
else if(id == R.id.nav_log_out)
{
SharedPreferences.Editor editor = getSharedPreferences("username",MODE_PRIVATE).edit();
editor.remove("UserUsername");
editor.commit();
Intent intent1 = new Intent(MainActivity.this,LoginActivity.class);
intent1.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
finish();
startActivity(intent1);
}
mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawer.closeDrawer(GravityCompat.START);
return true;
}
}
What can be the reason for this?? Can anyone help please? Thank you..
Got the solution.. Just tried to change the color of navigation item's text and it worked. Don't know why and how..
navigationView.setItemTextColor(ColorStateList.valueOf(Color.BLACK));
That may appear if you changed style of your layout in manifest. Check if you have defined all items from default style such as color especially.
来源:https://stackoverflow.com/questions/38989663/navigation-items-title-disappeared-when-clicked