How to set application fragments to portrait mode only?

前端 未结 2 1827
栀梦
栀梦 2021-01-06 06:22

I have an Android app which has a main activity and 3 Fragments which are tabs. I would like the application to remain in portrait mode at all times but I can\'t seem to get

2条回答
  •  甜味超标
    2021-01-06 07:01

    Try this..

    You can try with programmatically.

    After rootView in your java add this line getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    For Ex:

    View rootView = inflater.inflate(R.layout.activityxml, container, false);       
    getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    

    And also in your manifest change it android:configChanges="orientation|keyboardHidden" as android:configChanges="keyboardHidden"

    
    

提交回复
热议问题