Qt5.4 Beta, QtQuickControls and changing Android theme

Qt5.4 is coming closer...currently, 5.4 is in the Beta state. So today, I downloaded the Beta for Android on Windows and tried some things out.

In a previous post, I showed the new Android-style for the QtQuickControls module. Today, we will look how we could change the theme in a Qt-app on Android.

So, changing the theme....a Qt guru may think this will work with the QPalette class. With QPalette, you can define the background color, text color, ... in a platform-independent way. But QPalette won't be a good choice for Android...

On Android, we're facing a different, but very famous problem: the "Android fragmentation". Qt is supporting a minimum Android SDK version 10, current SDK version is 21 a.k.a. "Lollipop".
(by the way: QtQuickControls style for Android is working for SDK version 11+)
During the SDK version, the style of the native controls changed a lot! So, "native look-and-feel" on SDK v10 is very different than "native look-and-feel" on SDK v21. For this reason, QtQuickControls style extracts the Android style on the target device, during start-up. Controls will look allows the same coding with Java and XML...

If we want to change the theme of our Qt-Android app, we could apply these two approaches:

1. define theme in AndroidManifest.xml

First, create a AndroidManifest.xml file. In QtCreator, go to Project -> Run -> Deploy Configurations. Under the group "Advanced actions", click the "Create AndroidManifest.xml" button. A dialog will appear: click "Finish".

Now, open the AndroidManifest.xml (in directory "android") with a text editor. Copy and paste the following content in the "application" tag of AndroidManifest.xml:

android:theme="@android:style/Theme.Holo"
On my Amazon Kindle, this line of code will change the Android theme of my app from "Holo Light" to "Holo Dark".


2. define theme in the MainActivity

The second option is to set the theme dynamically during app startup. For this, create on own MainActivity.java and set the following, decribed in a mailing list post:


I hope, at least one option will work for you! Happy hacking!

Kommentare

Beliebte Posts aus diesem Blog

Native Look-and-Feel on Windows 10 Mobile with Qt / QML

Building QtWebKit Technology Preview 5 from Sources

Qt5 on Windows Phone - Current State