Whats the right approach to create or change color of a status bar?

kobra zlobra :

I have a quiet big problem with changing the color of my status bar. The device on which I working on is telling me android 5.1 but staff like windowTranslucentStatus or android:colorPrimaryDark or android:statusBarColor just does not work at all (translucent have like 20% dark transparence) and anything else does not work.

so it seems like it is something under android 5.0.

So I tried some applications - one did work because they made their own status bar in front of old ones. but the first thing I do not won't use the different app and second thing this app can not do animation notification which I using in my project

so I made a button with my color in front of my status bar but now I need to add there all icons. (i need there only wifi, bluetooth, battery, time.) that is it but I found that quite hard.

so now I am little bit stuck does anyone know hack how to change that color or how to somehow replicate notification icons? I do not need to slide notification bar I just need that to be seen.

kobra zlobra :

So last thing yes it does works this is ony one code whitch does not leave behind status bar shadow... do not know why but yes this was solution for me... i made in styles my background red... and on all screens (layouts) i add behind everything layout from edge to edge... so my background is now this layout... and real background is only for status bar...

solution like TranslucentStatus and little layout with my color did left shadow behind status bar so i never could get exactly that color which i needed... and solutions like statusbarcolor or primarydarkcolor programaticly or at styles never worked... so if you have this problem you can do this ugly solution... but it definitly work...

big thanks to @Muhammad Muzammil Sharif without him i will never get to this point... (3 people at my company tryed to do that whole week)

this is final wersion... now i would like to hide some of thoes system notifications... but i do not thing that is possible... thanks again to everyone enter image description here

enter image description here

enter image description here

so in all of your java activity you need this:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }

and at your styles.xml you need to set background color (this color will be your status bar color):

<style name="AppCompat" parent="Theme.AppCompat">
    <item name="android:colorBackground">@color/YOUR_STATUS_BAR_COLOR</item>
</style>

and at all your layouts you need to add layout which will be your background:

<LinearLayout
    android:background="@color/YOUR_BACKGROUND_COLOR"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom"
    />

of course if you would like use @color/just name... you need to set that at colors.xml:

<color name="YOUR_STATUS_BAR_COLOR">#cf031c</color>
<color name="YOUR_BACKGROUND_COLOR">#383838</color>

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=422935&siteId=1