Setting the orientation for only 1 fragment in my activity while the rest is in portrait

后端 未结 8 1096
难免孤独
难免孤独 2020-12-05 01:52

My app needs to be in portrait mode so I set it in the manifest by:

android:screenOrientation=\"portrait\"

But I just recently added anothe

8条回答
  •  爱一瞬间的悲伤
    2020-12-05 02:25

    In your fragment FragA :

    @Override
    public void onResume() {
        super.onResume();
        getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    
    }
    
    
    @Override
    public void onPause() {
        getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        super.onPause();
    }
    

    onPause method code ensure your activity back to portrait orientation

提交回复
热议问题