简体   繁体   English

底部导航栏片段多次

[英]bottom nav bar fragment multiple times

home fragment always on screen.i cant solve it.主页片段总是在屏幕上。我无法解决它。

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    BottomNavigationView bottomNavigationView = findViewById(R.id.bottomNavigationView);
    bottomNavigationView.setOnNavigationItemSelectedListener(this);
    bottomNavigationView.setSelectedItemId(R.id.homeFragment)

} 

/*@Override
protected void onStart() {
    if (currentUser==null){
        Intent welcomeIntent= new Intent(MainActivity.this,WelcomeActivity.class);
        startActivity(welcomeIntent);
        finish();
    }
    super.onStart();
}*/

homeFragment homeFragment = new homeFragment();
notificationFragment notificationFragment = new notificationFragment();
todolistFragment todolistFragment = new todolistFragment();
profileFragment profileFragment = new profileFragment();

@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {

    switch (item.getItemId()) {
        case R.id.homeFragment:
            getSupportFragmentManager().beginTransaction().replace(R.id.fragment, homeFragment).commit();
            return true;
        case R.id.notificationFragment:
            getSupportFragmentManager().beginTransaction().replace(R.id.fragment, notificationFragment).commit();
            return true;
        case R.id.todolistFragment:
            getSupportFragmentManager().beginTransaction().replace(R.id.fragment, todolistFragment).commit();
            return true;
        case R.id.profileFragment:
            getSupportFragmentManager().beginTransaction().replace(R.id.fragment, profileFragment).commit();
            return true;
    }
    return false;
}

} }

on home fragment it doubles.background texts are doesn't disappear.how can i solve it.what is the problem.i am using android studio with java在主页片段上它加倍。背景文本不会消失。我该如何解决。问题是什么。我正在使用 android 工作室和 java

1 1

2 2

these are the screen shots.main text view always appears这些是屏幕截图。主文本视图总是出现

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM