0

I have gradient value like this: linear-gradient(to right, #0072FF,#00C6FF).Can you tell me how to apply this to the Android status bar?

I have tried as shown below.But it is not working.

this.statusBar.backgroundColorByHexString('linear-gradient(to right, #0072FF,#00C6FF)');

This kind of simple one is working fine:

 this.statusBar.backgroundColorByHexString('#0072FF');
Sampath
  • 63,341
  • 64
  • 307
  • 441

2 Answers2

0

u can use Translucent status bar and set gradian background to a layout with same height with status bar.

for set status bar Translucent add this line to your theme:

<item name="android:windowTranslucentStatus">true</item>
faraz khonsari
  • 1,924
  • 1
  • 19
  • 27
0

You can set backgroud color gradiant like this:

 Window window = activity.getWindow();
 Drawable background = activity.getResources().getDrawable(R.drawable.gradient_theme);
 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
 window.setStatusBarColor(activity.getResources().getColor(R.color.transparent));
 window.setNavigationBarColor(activity.getResources().getColor(R.color.transparent));
 window.setBackgroundDrawable(background);

but it works for api 21 and bigger

and your gradiant theme should be like this in drawables :

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <gradient
                android:angle="90"
                android:startColor="@color/colorPrimary"
                android:endColor="@color/color_primary_100"
                android:type="linear" />
        </shape>
    </item>
</selector>
Meikiem
  • 1,876
  • 2
  • 11
  • 19
  • Hope this is for native Android no? I'm using Hybrid Ionic. – Sampath Jun 24 '17 at 19:55
  • Honestly, I used it some month ago but in an Android native code, Hope this works for you. if did not work tell we, we can find another way to do that ;) – Meikiem Jun 24 '17 at 19:57
  • It won't work with Ionic.We have to use this Cordova plugin for that.https://github.com/apache/cordova-plugin-statusbar – Sampath Jun 24 '17 at 19:59