如何设置应用程序片段只肖像模式?肖像、应用程序、片段、如何设置

由网友(杀无赦)分享简介:我有一个Android应用程序有一个主要活动和3个片断这是标签。我想在任何时候都保持在纵向模式下的应用程序,但我似乎无法得到这个工作。这是我已经试过了,按照另一个堆栈溢出职位,但我不知道我做错了什么....它需要使用,如果碎片是不同的?I have an Android app which has a main ac...

我有一个Android应用程序有一个主要活动和3个片断这是标签。我想在任何时候都保持在纵向模式下的应用程序,但我似乎无法得到这个工作。这是我已经试过了,按照另一个堆栈溢出职位,但我不知道我做错了什么....它需要使用,如果碎片是不同的?

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 this working. This is what I have tried, as per another stack overflow post, but I'm not sure what I'm doing wrong....does it need to be different if using fragments?

    <activity
        android:name="com.tutorial.test.activities.act1"
        android:label="@string/app_name" 
        android:screenOrientation="portrait"
        android:configChanges="orientation|keyboardHidden" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

感谢您!!

编辑:ViewPager是在FragmentActivity对此我设置screenOrientation如上

The ViewPager is on the FragmentActivity for which I am setting the screenOrientation as above.

推荐答案

试试这个..

您可以使用编程试试。

rootView 在Java中加入这一行 getActivity()setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

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

对于前

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

和也是在您的清单中改变它的android:configChanges =方向| keyboardHidden的android:configChanges =keyboardHidden

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

<activity
        android:name="com.tutorial.test.activities.act1"
        android:label="@string/app_name" 
        android:screenOrientation="portrait"
        android:configChanges="keyboardHidden" >
阅读全文

相关推荐

最新文章