简体   繁体   中英

Qt for Android - Statusbar color

Does anyone know a way to change the Android statusbar color of a Qt Application?

So far i've tried a lot of c++ solutions - all of them seem to fail, because that code does not run inside the main ui thread - and some xml adjustments in AndroidManifest.xml and styles.xml - that seems to influence at least the toolbar* but not the statusbar*..

Can someone maybe offer a c++ solution, or has anyone reached results with xml?

Thanks for your help!


*about the terms 'statusbar' and 'toolbar': Android calls two different ui elements 'statusbar'. So in this case, i'm calling one of them 'toolbar'. To clarify:

屏幕截图

Solved

Thanks to Volodymyr Shevchyk

Final solution: (mine is a bit hardcode-ish)

QtAndroid::runOnAndroidThread([=]()
{
    QAndroidJniObject window = QtAndroid::androidActivity().callObjectMethod("getWindow", "()Landroid/view/Window;");
    window.callMethod<void>("addFlags", "(I)V", 0x80000000);
    window.callMethod<void>("clearFlags", "(I)V", 0x04000000);
    window.callMethod<void>("setStatusBarColor", "(I)V", 0xffffffff); // Desired statusbar color
});                                                      // A R G B

Using extracts frome here and here .

Make sure, that you are on Qt version 5.7 or above. Otherwise QtAndroid::runOnAndroidThread won't work.

Note

If you're using white, or some other very bright color as background, the statusbar's text can be made a little darker using the following code:

    QAndroidJniObject decorView = window.callObjectMethod("getDecorView", "()Landroid/view/View;");
    decorView.callMethod<void>("setSystemUiVisibility", "(I)V", 0x00002000);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM