Navigation item name disappears when clicked

I created a box with a navigational view. I have a navigation item to which I invoke other actions.

The problem is when I click on the navigation element, another action is launched, and if I go back to the main activity and open the box, clicking on the name of the navigation element will disappear only I see the icon of the element.

the 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 could be the reason for this? Can anyone help? Thank..

+4
source share
2 answers

Got a solution. Just tried changing the color of the text of the navigation element, and it worked. I don’t know why and how ..

navigationView.setItemTextColor (ColorStateList.valueOf (Color.BLACK));

+2
source

, . , , , .

0

Source: https://habr.com/ru/post/1651495/


All Articles