0

So I want to make a transparent status bar. Problem is, the status bar always ends up being black. I used the setStatusBarColor() method but it didn't help. Here's what I end up with.Black status bar :|

and here's the activity's class:

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    /*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    }*/
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window w = getWindow(); // in Activity's onCreate() for instance
        w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        getWindow().setStatusBarColor(Color.TRANSPARENT);

    }else {
        FrameLayout relativeLayout = (FrameLayout) findViewById(R.id.mainStatusBar);
        relativeLayout.setVisibility(View.GONE);
    }
    CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
            .setDefaultFontPath("SourceSansPro-Regular.otf")
            .setFontAttrId(R.attr.fontPath)
            .build()
    );

}
@Override
protected void attachBaseContext(Context newBase) {
    super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}


}
Ahmad
  • 65
  • 1
  • 2
  • 11

3 Answers3

2

Use this code to make transparent

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

and Use NoActionBar Theme in your manifest.

Ashish
  • 997
  • 6
  • 20
0

check your app theme . It must be due theme.appCompact check this answer

Community
  • 1
  • 1
akshay_shahane
  • 4,423
  • 2
  • 17
  • 30
0

res/values/styles

<style name="AppTheme.ActionBar.Transparent" parent="AppTheme">
<item name="android:windowContentOverlay">@null</item>
<item name="windowActionBarOverlay">true</item>
<item name="colorPrimary">@android:color/transparent</item>

values-v21/styles.xml:

<style name="AppTheme.ActionBar.Transparent" parent="AppTheme">
<item name="colorPrimary">@android:color/transparent</item>

This will change the status bar color.

akshay_shahane
  • 4,423
  • 2
  • 17
  • 30
fsebek
  • 389
  • 2
  • 9