Landscape mode in Qt-Android application

梦想与她 提交于 2020-01-03 04:42:07

问题


I created a Qt/QML application and ported the application to Android. Now I'm able to run the application on the Android device. I want to fix the orientation mode to Landscape.

I manually edited the AndroidManifest.xml and set the android:screenOrientation="unspecified" to android:screenOrientation="sensorLandscape"

<activity
  android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation"
  android:name="org.qtproject.qt5.android.bindings.QtActivity"
  android:label="Engage"
  android:screenOrientation="sensorLandscape"
  android:launchMode="singleTop">

Each time when I deploy the project, the manifest is overwritten and reset to android:screenOrientation="unspecified"


回答1:


On Qt Forum the following solution is suggested:

Just go to the projects, running, click on details and create androidmanifest.xml, choose a directory. After that add it to your project if it didnt happen automatically and edit it. 4th line should look like this:

@<activity android:screenOrientation="unspecified" android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="@string/app_name">@ 

just change "unspecified" to "sensorLandscape" and save it.

It won't be overwritten every time you deploy.




回答2:


I got a solution for this.

Add a folder in your project folder. I have named 'android-sources'. Copy your AndroidManifest.xml from android-build and paste to 'android-sources' folder. Open .pro file and add the following

OTHER_FILES += \
    android-sources/AndroidManifest.xml
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android-sources

Then open the AndroidManifest.xml

change the orientation

android:screenOrientation="sensorLandscape"


来源:https://stackoverflow.com/questions/41546117/landscape-mode-in-qt-android-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!