In some applications I noticed that the status bar and navigational bar are transparent however, not completely. I do not know if this is a background color or something else. Would someone tell me how to implement this? Thank you.
Asked
Active
Viewed 1.3k times
3 Answers
11
You can use this two method:
getWindow().setStatusBarColor(Color.parseColor("#20111111"));
getWindow().setNavigationBarColor(Color.parseColor("#20111111"));

Satan Pandeya
- 3,747
- 4
- 27
- 53

ak sacha
- 2,149
- 14
- 19
-
Thanks, do you know the exact color Google uses? – Lord Goderick Jan 13 '17 at 13:16
-
1i dont know exact color but Color.parseColor("#20111111") this will help you. – ak sacha Jan 13 '17 at 13:18
-
Thanks, this is very close. – Lord Goderick Jan 13 '17 at 13:19
-
1Happy Coding :) – ak sacha Jan 13 '17 at 13:20
-
7I'm getting opaque color – Choletski Apr 10 '19 at 13:02
6
There is a bit more to it than just setting the navigation bar color and the statusbar color, you have to actually have your content appear underneath both.
I use the following method in my utils class to set it in the activity before setContentView
public static void setWindowStatusNav(android.view.Window window, int statusbarColor, int navbarColor) {
int flags = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT || Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT_WATCH) {
window.getAttributes().flags |= flags;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
int uiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
window.getDecorView().setSystemUiVisibility(uiVisibility);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.getAttributes().flags &= ~flags;
window.setStatusBarColor(statusbarColor);
window.setNavigationBarColor(navbarColor);
}
}
Use it in your activity:
public class MyActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int statusBarColor = android.graphics.Color.parseColor("#40FF0000");
int navBarColor = android.graphics.Color.parseColor("#6E00FF00");
MyUtils.setWindowStatusNav(getWindow(), statusBarColor, navBarColor);
setContentView(R.layout.my_activity);
}
}
To hide the navigation and status bars, call this method:
public static void setWindowStatusNavHidden(android.view.Window window) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
int uiVisibility = window.getDecorView().getSystemUiVisibility();
uiVisibility |= View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
window.getDecorView().setSystemUiVisibility(uiVisibility);
}
}
Usage complete:
public class MyActivity extends AppCompatActivity {
static boolean statusNavVisible = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int statusBarColor = android.graphics.Color.parseColor("#40FF0000");
int navBarColor = android.graphics.Color.parseColor("#6E00FF00");
MyUtils.setWindowStatusNav(getWindow(), statusBarColor, navBarColor);
setContentView(R.layout.my_activity);
Button btnShowHide = findViewById(R.id.my_button);
btnShowHide.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (statusNavVisible) {
statusNavVisible = false;
MyUtils.setWindowStatusNavHidden(getWindow());
} else {
statusNavVisible = true;
MyUtils.setWindowStatusNav(getWindow(), statusBarColor, navBarColor);
}
}
});
}
}

Pierre
- 8,397
- 4
- 64
- 80
1
If you just want to make it Translucent, Add this in your theme.
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
If your also want it to Hide and to make your activity full screen.
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
and in your Activity onCreate Add.
requestWindowFeature(Window.FEATURE_NO_TITLE);
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
);
if (Build.VERSION.SDK_INT >= 30) {
findViewById<ConstraintLayout>(R.id.main_activity_parent).windowInsetsController?.hide(WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars())
} else {
findViewById<ConstraintLayout>(R.id.main_activity_parent).systemUiVisibility =
View.SYSTEM_UI_FLAG_LOW_PROFILE or
View.SYSTEM_UI_FLAG_FULLSCREEN or
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
}

Saad Ali Shujaat
- 419
- 3
- 6