Reputation: 1
I am still very new to Qt and qml and struggle with getting the color of the statusbar and navigationbar changed on deployed andriod apps with qtquick.
I have found that it is possible to change the color of the statusbar via QtAndroid::runOnAndroidThread, but that seems to not work for more recent Qt Versions.
I have found out that this code is probably the one to use now (https://doc-snapshots.qt.io/qt6-dev/qnativeinterface-qandroidapplication.html#runOnAndroidMainThread) :
QAndroidApplication::runOnAndroidMainThread(const std::function<QVariant ()> &runnable, const QDeadlineTimer timeout = QDeadlineTimer::Forever)
with #include .
But unfortunately there aren't any examples I could find on the internet how and where in the code this function is used. And more specifically, how would I use this code to change the color of the status- and navigationbar?
I would really appreciate help here.
Upvotes: 0
Views: 230
Reputation: 1
Example: showing toast message (running this not in UI-thread will cause exception)
QString message = "Hello from Toast!";
const int duration = 1; // 0 - short, 1 - long
auto interface = qApp->nativeInterface<QNativeInterface::QAndroidApplication>();
interface->runOnAndroidMainThread([message, duration, interface] {
auto javaMessage = QJniObject::fromString(message);
auto toast = QJniObject::callStaticObjectMethod(
"android/widget/Toast",
"makeText",
"(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;",
interface->context(),
javaString.object(),
jint(duration)
);
toast.callMethod<void>("show");
});
Upvotes: 0