单击时导航项的标题消失

Navigation item's title disappeared when clicked

我已经创建了带导航视图的抽屉。我有导航项目,我正在调用其他活动。

问题是当我点击导航项时,另一个 activity 启动,如果我返回主 activity 并打开一个抽屉,点击的导航项的标题消失了只有我可以查看项目的图标。

代码:

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

}

这可能是什么原因??有人可以帮忙吗?谢谢..

找到解决方案了。只是尝试更改导航项文本的颜色并且成功了。不知道为什么以及如何..

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

如果您在清单中更改了布局样式,则可能会出现这种情况。检查您是否定义了默认样式的所有项目,尤其是颜色。