Implementing back button in webview fragment

前端 未结 4 789
花落未央
花落未央 2021-01-25 23:13

I want to implement the back button to my app. I\'m using fragments that each show a different webview. Right now if I press the back button, it closes the app no matter where I

4条回答
  •  被撕碎了的回忆
    2021-01-25 23:51

    FragmentManager fragmentManager = getSupportFragmentManager();
                    FragmentTransaction fragmentTransaction = fragmentManager
                            .beginTransaction();
                    First first_act = new First();
    
                    fragmentTransaction.replace(R.id.fragment_container,
                            first_act);
                    fragmentTransaction.addToBackStack("first_act");
                    fragmentTransaction.commit();
    

    Add these code in mainactivity , and then use this onbackpressed in fragment

    @Override
      public void onBackPressed() {
    
      }
    

提交回复
热议问题