Wie kann ich den Querformatmodus für einige Ansichten in meiner Android-App deaktivieren?
Antworten
Zu viele Anzeigen?Fügen Sie den folgenden Befehl zu Ihrem Projekt hinzu,
npm install
npm i react-native-orientation-locker
Dann verwenden Sie eine Manifestklasse wie, React_Native (Ihr Projektordner)/ Android/app/src/main/AndroidManifest.xml :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.payroll_react">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
Sie können erzwingen, dass Ihre spezielle Aktivität immer im Hochformat bleibt, indem Sie dies in Ihrem manifest.xml Datei:
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"></activity>
Sie können auch erzwingen, dass Ihre Aktivität im Hochformat bleibt, indem Sie folgende Zeile in die onCreate()-Methode Ihrer Aktivität schreiben:
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="in.co.nurture.bajajfinserv">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Wir können die Aktivität im Hoch- oder Querformat einschränken, indem wir das Attribut oder android:screenOrientation
.
Wenn wir mehr als eine Aktivität in unserem Programm haben, dann haben wir die Freiheit, eine beliebige Aktivität in einem beliebigen Modus einzuschränken, ohne dass dies die anderen beeinträchtigt, was Sie nicht wollen.
Bei mir hat es funktioniert. Versuchen Sie, diesen Code in der AndroidManifest-Datei hinzuzufügen:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:screenOrientation="portrait"
android:theme="@style/AppTheme">
....
....
</application>