onBackPressed() method not triggered in AppCompatActivity

前端 未结 6 856
囚心锁ツ
囚心锁ツ 2021-02-13 23:26

AppCompatActivity onBackPressed() method fails to trigger in my activity.

I see the back arrow button and get the animation when pressing it, but nothing else happens. a

6条回答
  •  臣服心动
    2021-02-13 23:58

    back_button on the actionbar

    this will wok

    Toolbar toolbar=(Toolbar) findViewById(R.id.appBar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    
    @Override
    public void onBackPressed() {
    super.onBackPressed();
    this.finish();
    

    }

    or set which activity load when click back

    
    

提交回复
热议问题