Use Holo theme in Qt Android application

2019-04-07 17:36发布

问题:

I have a Qt Android application, and I want to set its theme to be Holo (i.e. the dark variant, not Holo Light). Here's a comparison between Holo Dark theme (left), and how my application looks now (right):

I'm using Qt 5.2.0, and I'm using Qt/C++ (i.e. not QML), but I'm interested for any way that works, regardless of Qt version or whether it's QML or C++.

Edit: I know that using Ministro, it will create pixmaps for all widgets using the "native" theme, but is it possible to tell Ministro which theme to use?

回答1:

Edit: Holo Dark can now be selected as of Qt 5.4 by adding android:theme="@android:style/Theme.Holo" to <application> in AndroidManifest.xml.

This works with Qt 5.4, but not with Qt 5.2, with Qt 5.2, the theme is always the phone's default theme no matter what you specify for android:theme in the manifest.

So in AndroidManifest.xml, find the <application> node, and change it to:

<application android:theme="@android:style/Theme.Holo" ...

This is not available for the moment for QtQuickControls, although it was brought to Qt 5.2 for the QtWidgets.

The former is on BogDan's TODO list for 5.3. See his blog for details:

Qt on Android Episode 1

Here you can find a couple of screenshots from my friend's system.

Non-native

Native

QtCreator



回答2:

Bu using Ministro your application gets a dependency to the Ministro App. I think this is an disadvantage because the extra dependency will cause the Application to check on startup if Ministro is installed on your device yes or no. If it is not installed the user is forced to install it over the Android Play Store.

Instead of using Ministro I would set a custom stylesheet which imatetes the holo theme.

QApplication::setStyleSheet(const QString & sheet)

There is a repository on GIT here, which imitates the various android themes. It shouldn't be to difficult adapt a holo .css file to a Qt stylesheet (.qss) file.



回答3:

According to Google Style guide, you need to set it into the AndroidManifest.xml:

To set a theme for all the activities of your application, open the AndroidManifest.xml file and edit the tag to include the android:theme attribute with the style name. For example:

 <application android:theme="@android:style/Theme.Holo"/>

If you want the light theme (the default one is the dark one), you have to write this instead:

 <application android:theme="@android:style/Theme.Holo.Light"/>