0
votes

I am developing an android app (API 19) with qml (Qt 5.3.1, Mac OS X 10.8.5). The fullscreen mode works, but there is a little problem. The navigation bar is hidden, but the app is not using this space (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
}

I tried adding android:theme="@android:style/Theme.NoTitleBar.Fullscreen" to AndroidManifest.xml, but no solution.

Tested with simulator and device. Any ideas?

3

3 Answers

1
votes

You should also set System UI Visibility flags:

In Android code:

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);

In Qt C++ code:

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);
});

You can get flag codes from https://developer.android.com/reference/android/view/View.html

0
votes

The problem is resolved in upcoming version 5.3.2. http://qt-project.org/forums/viewthread/46400/

0
votes

addional information for Dovranito answer you have to remove if there is in androidmanifest.xml , "android:theme= " definition

for example your androidmanifest.xml is

<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">

to

<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" 
android:label="superslot" android:extractNativeLibs="true">

and in main.cpp add a function and its declaration

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);
    });
}

you can call this function after create mainwindow

setFullScreenMode(true);

Finnaly, you dont forget add main.cpp, #include <QtAndroidExtras>, .pro file add QT += androidextras

thats all.