0

I have managed to get a fully transparent status bar but I would like a semi-transparent one instead. Below is the code I added to achieve a fully transparent status bar.

In my styles.xml I added the following:

        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">true</item>

In my activity.xml:

    android:fitsSystemWindows="true"

In the onCreate of my activity.java:

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

This is what I would like to achieve: Semi-Transparent Status Bar

Edric
  • 18,215
  • 11
  • 68
  • 81
Raf A
  • 125
  • 9
  • 1
    Try full screen `getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);` – exploitr Dec 24 '19 at 15:55
  • This works but the status bar isn't visible at first - I have to pull it down. Can I get it to permanent stay there? – Raf A Dec 24 '19 at 16:31
  • 1
    I guess it's Android's immutable behavior. When you're asking for FULLSCREEN, they'll hide the status bar for normal causes. – exploitr Dec 24 '19 at 17:30
  • 1
    Well, I found a reflection hack: https://stackoverflow.com/a/14320900/8572503 .However, it might not be your case - still try. – exploitr Dec 24 '19 at 17:40
  • I couldn't get this to work either. I'm going to stick with your first suggestion. – Raf A Dec 26 '19 at 11:56
  • I've written an answer, you can make that one as accepted – exploitr Dec 26 '19 at 14:14

3 Answers3

1

There can be multiple possible solutions for your problem :

1. Switch to fullscreen window

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

2. The XML way

<style name="AppTheme.MainActivity" parent="AppTheme">
    <item name="colorPrimary">#ffffff</item>
    <item name="colorPrimaryDark">#ebebeb</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="windowNoTitle">true</item>
</style>
exploitr
  • 762
  • 1
  • 12
  • 23
0

create new color inside colors.xml

<color name="blackT">#88000000</color>

then inside style.xml change primary dark color

<item name="colorPrimaryDark">@color/blackT</item>

0

Here is some option that you can implement on your code,

Option 1: On your xml file

 android:background ="#88676767" or "#88000000"

Option 2. On your image view or any other view

view.setColorFilter(Color.argb(150, 155, 155, 155),   Mode.SRC_ATOP);

Option 3: On your layout

LinearLayout ll = (LinearLayout) findViewById(R.id.test_layout);
Drawable dd = getResources().getDrawable(R.drawable.test);
dd.setAlpha(50);
ll.setBackgroundDrawable(dd);

It might be helpful for you.

Horrorgoogle
  • 7,760
  • 11
  • 45
  • 79