Skip to content

Instantly share code, notes, and snippets.

@bulwinkel
Created August 18, 2016 13:08
Show Gist options
  • Save bulwinkel/e669cacd6bea1347b932e26c56d0ae8e to your computer and use it in GitHub Desktop.
Save bulwinkel/e669cacd6bea1347b932e26c56d0ae8e to your computer and use it in GitHub Desktop.
Android Window Utilities
import android.annotation.TargetApi;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.view.Window;
import android.view.WindowManager;
public class Windows {
private Windows() {
//no instances
}
/**
* Credit to the answer marked correct:
* http://stackoverflow.com/questions/33668668/coordinatorlayout-not-drawing-behind-status-bar-even-with-windowtranslucentstatu
*/
public static void setTranslucentStatusBar(Window window) {
if (window == null) return;
int sdkInt = Build.VERSION.SDK_INT;
if (sdkInt >= Build.VERSION_CODES.LOLLIPOP) {
setTranslucentStatusBarLollipop(window);
} else if (sdkInt >= Build.VERSION_CODES.KITKAT) {
setTranslucentStatusBarKiKat(window);
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static void setTranslucentStatusBarLollipop(Window window) {
window.setStatusBarColor(
ContextCompat.getColor(window.getContext(), android.R.color.transparent));
}
@TargetApi(Build.VERSION_CODES.KITKAT)
private static void setTranslucentStatusBarKiKat(Window window) {
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment