=====================================
問題環境
OS:Windows 10
開發平台:Android
React Native : 0.38.0
日期:2016/12/09
=====================================
問題:
最近在找API讓螢幕可以翻轉並且全螢幕。
但是都沒有實際作用,因此我打算直接從Android的設定檔下去設定。
建議如果你是要使用多平台的話,還是找個好用的API吧。
首先我們要設定AndroidManifext.xml
檔案位置:ProjectName\android\app\src\main\AndroidManifest.xml
<application
android:name=".MainApplication"
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme"
android:screenOrientation="landscape" <----翻轉螢幕
android:configChanges="orientation" <----翻轉螢幕
>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" <----全螢幕設定
>
<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>
檔案位置:ProjectName\android\app\src\main\java\...\MainActivity.java
接著保持螢幕常開和強制翻轉
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//保持螢幕常開
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
//強制螢幕旋轉
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
沒有留言:
張貼留言