In Fragment on back button pressed Activity is blank

前端 未结 11 1735
囚心锁ツ
囚心锁ツ 2020-11-29 20:04

I have an Activity and many fragments inflated in same FrameLayout



        
11条回答
  •  甜味超标
    2020-11-29 20:22

    You can override onBackPressed and check to see if there is anything on the backstack.

    @Override
    public void onBackPressed() {
        int fragments = getFragmentManager().getBackStackEntryCount();
        if (fragments == 1) { 
            // make layout invisible since last fragment will be removed
        }
        super.onBackPressed();
    }
    

提交回复
热议问题