4

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..

  • This can have something to do with the selected color of the navigation item. To check this, change the background color of the navigation drawer. – Marcel50506 Aug 17 '16 at 07:01

2 Answers2

2

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));

  • you saved my day , i tried changing the colors of items in xml file to black,but it wasnt working, the menu items were just disappearing into the layout color. but the same coloration in activity.java file made the view items show up – Antroid Aug 09 '17 at 14:03
  • Shouldn't this be handled in the XML somewhere as opposed to code? Is there a style which can correct this? – lcj Jun 15 '21 at 20:20
0

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.

adampicker
  • 29
  • 1
  • 1
  • 6