我正在使用qml(Qt 5.3.1,Mac OS X 10.8.5)开发一个Android应用(API 19)。全屏模式可以使用,但是存在一些问题。导航栏处于隐藏状态,但应用程序未使用此空间(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,但没有解决方案。
经过模拟器和设备测试。有什么想法吗?
您还应该设置系统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获取标志代码>
此问题在即将发布的版本5.3.2中已解决。http://qt-project.org/forums/viewthread/46400/