Photo by Sabri Tuzcu on Unsplash

Android Notes 1: Transparent Status Bar on Fragment and Activity [UPDATED]

Kuray Ogun
FreakyCoder Software Blog

--

Updated: 28 Dec, 2019

After using other libraries for just translating status bar at Android, I found a method.

This method does not require any library or anything, just use this code segment into your @OnCreate method and taa-daaa :)

Code:

@OnCreate{  
// FullScreen getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
// XML Part
<item name="android:windowTranslucentStatus">true</item>

Gist:

Fragment Usage

if you’re working on Fragment, you should put this code segment on your activity’s @OnCreate method.

Example: LoginActivity + LoginActivityFragment, you should put this code into LoginActivity, not the fragment one.

Activity Usage

if you’re working on just normal Activity, you should just put the code which should be in styles.xml.

Completely Transparent Status Bar

Be sure to also set the transparency in /res/values-v21/styles.xml:

<item name="android:statusBarColor">@android:color/transparent</item>

Or set the transparency programmatically:

getWindow().setStatusBarColor(Color.TRANSPARENT);

Annotation: This method just works on API 21 and above.

Note: You should add the code segment in styles.xml

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

Note 2: This method just works on API 19 and above.

if you have any question, ask me :)

--

--