gpt4 book ai didi

android - 单击时导航项的标题消失

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:14:35 24 4
gpt4 key购买 nike

我已经创建了带导航 View 的抽屉。我有导航项目,我正在调用其他 Activity 。

问题是当我点击导航项时,其他 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));

关于android - 单击时导航项的标题消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38989663/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com