底部导航栏片段多次

时间:2020-04-30 20:17:32

标签: java android

主页片段始终在屏幕上。我无法解决它。

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

}

在家庭片段上加倍。背景文本没有消失。我该如何解决。是什么问题。我正在将android studio与java一起使用

1 个答案:

答案 0 :(得分:0)

1

2

这些是屏幕截图。主文本视图始终出现