2016-10-30 55 views
5

我能找到的唯一的事情就是用這樣的:如何將應用程序設置爲僅肖像?

android:configChanges="orientation" 
    android:screenOrientation="portrait" 

,但它保持正常。我的清單:

?xml version="1.0" encoding="utf-8"?> 

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:configChanges="orientation" 
    android:screenOrientation="portrait" 
    android:theme="@style/AppTheme"> 
    <activity android:name=".MainActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

回答

16

如問題所示: I want my android application to be only run in portrait mode?

應設置configChangesscreenOrientation標誌的每個活動,而不是在你的表現的根源。

因此,它應該是這樣的:

<activity android:name=".MainActivity" 
    android:configChanges="orientation" 
    android:screenOrientation="portrait"> 
    <intent-filter> 
     <action android:name="android.intent.action.MAIN"/> 

     <category android:name="android.intent.category.LAUNCHER"/> 
    </intent-filter> 
</activity> 
0

android:screenOrientation必須在<activity>塊。 android:configChanges也不適用於<application>,但<activity>也適用。

相關問題