【问题标题】:Issue with fullscreen mode in android with Qt 5.3.1使用 Qt 5.3.1 在 android 中出现全屏模式问题
【发布时间】:2014-10-10 00:37:12
【问题描述】:

我正在使用 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,但没有解决方案。

用模拟器和设备测试。有什么想法吗?

【问题讨论】:

    标签: android qt qml fullscreen


    【解决方案1】:

    该问题在即将发布的 5.3.2 版本中得到解决。 http://qt-project.org/forums/viewthread/46400/

    【讨论】:

      【解决方案2】:

      您还应该设置系统 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获取标志代码

      【讨论】:

        【解决方案3】:

        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 &lt;QtAndroidExtras&gt;、.pro 文件添加 QT += androidextras

        仅此而已。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2023-03-26
          • 1970-01-01
          • 2013-09-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-03-29
          相关资源
          最近更新 更多