gpt4 book ai didi

android - 如何将应用程序 fragment 设置为仅纵向模式?

转载 作者:太空狗 更新时间:2023-10-29 15:33:34 25 4
gpt4 key购买 nike

我有一个 Android 应用程序,它有一个主要 Activity 和 3 个标签 fragment 。我希望该应用程序始终保持纵向模式,但我似乎无法正常工作。根据另一篇堆栈溢出帖子,这是我尝试过的方法,但我不确定自己做错了什么......如果使用 fragment ,是否需要有所不同?

    <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,如上所示。

最佳答案

试试这个..

您可以尝试以编程方式

在您的 java 中的 rootView 之后添加此行 getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

对于Ex:

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

同时在您的 list 中将其 android:configChanges="orientation|keyboardHidden" 更改为 android:configChanges="keyboardHidden"

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

关于android - 如何将应用程序 fragment 设置为仅纵向模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21950070/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com