我创建了一个登录布局(从 MainActivity 开始)
public class MainActivity extends AppCompatActivity implements View.OnClickListener, BottomNavigationView.OnNavigationItemSelectedListener{
private Button regiBtn;
private Button loginBtn;
private Button forgotBtn;
private EditText loginEmail;
private EditText loginPwd;
public static FirebaseAuth mAuth;
public static FirebaseUser currentUser;
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
Fragment fragment = null;
switch (menuItem.getItemId()){
case R.id.navigation_profile:
fragment = new ProfileFragment();
break;
case R.id.navigation_task:
fragment = new TaskFragment();
break;
case R.id.navigation_leadingboard:
fragment = new LeadingBoardFragment();
break;
case R.id.navigation_home:
fragment = new HomeFragment();
break;
}
return loadFragment(fragment);
}
private boolean loadFragment(Fragment fragment){
if(fragment!=null){
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, fragment)
.commit();
return true;
}
return false;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAuth = FirebaseAuth.getInstance();
// check if user is signed in (non-null)
currentUser = mAuth.getCurrentUser();
}
正如您所看到的,当用户登录时,MainActivity 将其布局更改为底部导航布局,用户可以在其中选择要执行特定操作的部分。
我想将当前活动(应该是MainActivity对吧?)布局更改为activity_main(用户执行登录功能的地方),布局确实改变了,但按钮无法工作。布局更改为activity_main(用户登录)->activity_dashboard(带有片段)->main_activity(当用户从片段注销时)我想知道我哪里出了问题。
胡说叔叔
一只斗牛犬
相关分类