Change StatusBar color and how to setAlpha

3

Well, I've been trying for a while to put the alpha to the status bar but I can not do it, I want to do as well as the toolbar with setAlpha ()

toolbar.getBackground().setAlpha(intColor);

but can not find a similar property for the status bar, try the following code but I have achieved my goal;

getWindow().setStatusBarColor(Color.alpha(intColor));

Thanks in advance.

    
asked by Gunnar 18.06.2016 в 14:36
source

2 answers

1

Remember that window.setStatusBarColor() works for Android 5.0 and later. Use the Color.argb() method to define the alpha :

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
       int alpha = 150; //valor 0 a 255.
 getWindow().setStatusBarColor(Color.argb(alpha, 250, 120, 0));


    }

With respect to the method getBackground() of toolBar it is better to use setBackgroundDrawable(colorDrawable);

You define a color in colors.xml to create the ColorDrawable:

  ColorDrawable colorDrawable = new ColorDrawable(getResources().getColor(R.color.mi_color));

You define an alpha between 0 and 255 for your ColorDrawable :

colorDrawable.setAlpha(150);

defines the ColorDrawable to your toolBar:

mToolbar.setBackgroundDrawable(colorDrawable);
    
answered by 18.06.2016 / 16:33
source
0

Try adding the color by Hexagesimal and adding two more characters at the beginning you get the alpha. Here a table about these two characters:

     Hex Opacity Values
     100% — FF
     95% — F2
     90% — E6
     85% — D9
     80% — CC
     75% — BF
     70% — B3
     65% — A6
     60% — 99
     55% — 8C
     50% — 80
     45% — 73
     40% — 66
     35% — 59
     30% — 4D
     25% — 40
     20% — 33
     15% — 26
     10% — 1A
     5% — 0D
     0% — 00
    
answered by 18.06.2016 в 20:05