我正在开发一个带有qml的Android应用程序(API 19)(Qt 5.3.1,Mac OS X 10.8.5)。全屏模式有效,但有一点问题。导航栏已隐藏,但应用未使用此空间(http://i.stack.imgur.com/2UXBK.jpg)。
的main.cpp
...
QApplication app(argc, argv);
QQuickView viewer1(QUrl(QStringLiteral("qrc:///main.qml")));
viewer1.setResizeMode(QQuickView::SizeRootObjectToView); // no effect
viewer1.showFullScreen();
return app.exec();
...
main.qml
import QtQuick 2.2
Rectangle {
color: "red"
width: 100
height: 100
}
我尝试将android:theme =“@ android:style / Theme.NoTitleBar.Fullscreen”添加到AndroidManifest.xml,但没有解决方案。
使用模拟器和设备进行测试。有什么想法吗?
答案 0 :(得分:1)
您还应该设置系统UI可见性标志:
在Android代码中:
View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);
在Qt C ++代码中:
QtAndroid::runOnAndroidThread([=]()
{
QAndroidJniObject window = QtAndroid::androidActivity().callObjectMethod("getWindow", "()Landroid/view/Window;");
QAndroidJniObject decorView = window.callObjectMethod("getDecorView", "()Landroid/view/View;");
int flags = 0x00000002 | 0x00000400 | 0x00000100 | 0x00000200 | 0x00000004 | 0x00001000;
decorView.callMethod<void>("setSystemUiVisibility", "(I)V", flags);
});
您可以从https://developer.android.com/reference/android/view/View.html
获取标志代码
答案 1 :(得分:0)
问题在即将发布的5.3.2版中得到解决。 http://qt-project.org/forums/viewthread/46400/
答案 2 :(得分:0)
Dovranito答案的其他信息 您必须删除androidmanifest.xml中的“ android:theme =“定义
例如您的androidmanifest.xml是
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:label="superslot" android:extractNativeLibs="true">
到
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication"
android:label="superslot" android:extractNativeLibs="true">
并在main.cpp中添加一个函数及其声明
void setFullScreenMode(bool on)
{
QtAndroid::runOnAndroidThread([on]{
QAndroidJniObject window = QtAndroid::androidActivity().callObjectMethod("getWindow", "()Landroid/view/Window;");
QAndroidJniObject decorView = window.callObjectMethod("getDecorView", "()Landroid/view/View;");
int flags = 0x00000002 | 0x00000400 | 0x00000100 | 0x00000200 | 0x00000004 | 0x00001000;
decorView.callMethod<void>("setSystemUiVisibility", "(I)V", flags);
});
}
您可以在创建主窗口后调用此函数
setFullScreenMode(true);
最后,您不会忘记添加main.cpp,#include <QtAndroidExtras>
、. pro文件并添加QT += androidextras
仅此而已。