QT on Android: let Qt Widgets and QT Quick apply full screen display

Source: Internet
Author: User

Android system version is many, newer 4.4, older 2.3, are used by people. Qt on Android development Android app, default on Android device is non-fullscreen. Some applications require full-screen display, such as games. So how do we do this?

   &NBSP, final article poll

We need to split the Android system version.

Android 2.x

For systems before 4.0, such as 2.2, 2.3, you can modify the Androidmanifest.xml file to achieve full screen.

first, you need to generate a Androidmanifest.xml file for the Qt on Android app, specifically referring to the Qt on Android: a text-to-text explanation of the whole process of Hello world. Create the Androidmanifest.xml as follows:


Click the button labeled 7 to create a androidmanifest.xml file. This file is generated by default in the Qt project directory under the Android subdirectory.

Then you need to open the Androidmanifest.xml file, locate the Activity tag, and add the following attribute to it:

Android:theme= "@android: Style/theme.notitlebar.fullscreen"

Note the spacing between the front and back attributes.

Run your Qt on Android app on a 2.x system, it's full-screen, not even the title bar.

Android 4.x

Android version after 4.0, the previous way to set the active theme is invalid. We need to set a full-screen window tag for Activity in Java code.

This is simple in the Java-authored Android app, just add the following code to the Activity's OnCreate () method:

GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_FULLSCREEN);

But the Qt on Android app is a little bit more complicated.

Step by step, this time with our Qt Quick App as an example to illustrate, first refer to the Qt Quick's Hello World text detailed article to create a project, I demonstrate the need, or helloqtquickapp-based modification.

First look at the changes before (I run on the 4.0.3 system's set-top box):


Notice the status bar at the bottom of the picture.

Generate Androidmanifest.xml

Refer to the previous section and set the Theme property of the Activity.

Add a Java file for a Qt project

QT on Android application, qt part of the code in a JNI way through the Java code started. In order to be able to launch QT code into the QT world, the QT Framework provides the QPA layer as well as the necessary Activity, application implementations. For details, refer to "Qt on Android Episode 1 (translator)" and "Qt for Android deployment process Analysis " two articles.

Here is a brief explanation of Qt 5.2.0 as an example.

A brief analysis of Qtactivity

If you observe the Androidmanifest.xml file, you will find the activity tag inside, and the activity name specified is: "Org.qtproject.qt5.android.bindings.QtActivity". Yes, that's it! It is provided by the QT framework, your QT on Android app's entrance. The location of qtactivity is here:

C:\qt\Qt5.2.0\5.2.0\android_armv5\src\android\java\src\org\qtproject\qt5\android\bindings\QtActivity.java

Interested can open this Java file for a look.

Here is an excerpt from Qtactivity.java's onCreate function:

...    @Override public    void OnCreate (Bundle savedinstancestate)    {        super.oncreate (savedinstancestate);        try {            setTheme (Class.forName ("Android. R$style "). Getdeclaredfield (Qt_android_default_theme). GETINT (null));        } catch (Exception e) {            e.printstacktrace ();        }        if (Build.VERSION.SDK_INT >) {            try {                requestwindowfeature (Window.class.getField ("Feature_action_bar "). GetInt (null));            } catch (Exception e) {                e.printstacktrace ();            }        } else {            requestwindowfeature (window.feature_no_ TITLE);        }    ...    } ...

As you can see, Qtactivity distinguishes the SDK version, more than 10 of the request Feature_action_bar features, less than 10 (Android 2.3 and below) version do not title (too ugly, only show the app name, wood what use).

You know, Qt Creator can compile Java source code (by calling Ant), Qtactivity is compiled into your APK. So, we can also add our own Java code.

To add a full-screen tag, we need to inherit the Qtactivity class to implement a new Activity. Of course if you want to rough solve this problem, you can directly modify the Qtactivity.java, directly add a line of code. What code? Look underneath.

Implement Qtfullscreenactivity

Qtfullscreenactivity inherits from the Qtactivity class, the code is very simple. As follows:

Package An.qt.helloqtquickapp;import Android.content.context;import Android.content.intent;import Android.app.pendingintent;import Android.util.log;import Android.os.bundle;import Android.view.WindowManager; public class Qtfullscreenactivity extends org.qtproject.qt5.android.bindings.qtactivity{    private final static String TAG = "Qtfullscreen";    @Override public    void OnCreate (Bundle savedinstancestate) {          super.oncreate (savedinstancestate);          GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_FULLSCREEN);    }}

The line that starts with "GetWindow ()" In the code above is set to full-screen markup.

add qtfullscreenactivity to Pro file

I put the Qtfullscreenactivity.java file under android/src/an/qt/helloqtquickapp/, so the relevant part of the pro file is Jiangzi:

Other_files + =     android/androidmanifest.xml     Android/src/an/qt/helloqtquickapp/qtfullscreenactivity.java

Note that the package name in the Java code (qtfullscreenactivity first row), and the path is strictly matched, the Java class name and the source code file name strictly match.

Then you can see the following project views:



Modify Androidmanifest.xml

This is the last step of the change.

We implement the Activity name is qtfullscreenactivity, so, androidmanifest.xml file also want to modify, consistent. See below:

<?xml version= ' 1.0 ' encoding= ' utf-8 '? ><manifest xmlns:android= "http://schemas.android.com/apk/res/ Android "     android:versioncode=" 1 "     android:installlocation=" Auto "     package=" an.qt.helloQtQuickApp "     android:versionname= "1.0" >    <application         android:name= " Org.qtproject.qt5.android.bindings.QtApplication "         android:label=" @string/app_name ">        <activity             android:name= "an.qt.helloQtQuickApp.QtFullscreenActivity"             android:configchanges= "orientation|uimode| Screenlayout|screensize|smallestscreensize|locale|fontscale|keyboard|keyboardhidden|navigation "             android: Theme= "@android: Style/theme.notitlebar.fullscreen"             android:label= "@string/app_name"             android: screenorientation= "Unspecified" >            <intent-filter>...</manifest>


OK, so far, all the changes are ready. Run our Helloqtquickapp.

Here are the effects that are now running:



Okay, here we go.    

    Please give me the final article poll

Other articles in this series:

  • Qt on Android: text-to-detail Hello world whole process
  • Introduction to the development of Qt 5.2 for Android under Windows
  • Qt for Android deployment process Analysis
  • QT on Android: output qt Debug information to Logcat
  • Qt on ANDROID:QT 5.3.0 released for Android improvement instructions
  • Qt on Android episode 1 (translation)
  • Qt on Android episode 2 (translation)
  • Qt on Android episode 3 (translation)
  • Qt on Android episode 4 (translation)
  • Qt for Android compiled pure C project
  • Windows under Qt for Android compiled Android C language executable program
  • Qt on Android:android SDK installation
  • Qt on android:http download and JSON parsing
  • Qt on Android Settings app is named Chinese

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.