Created
April 16, 2015 15:27
-
-
Save tabrindle/edcc019de52b96a64390 to your computer and use it in GitHub Desktop.
Add to MainActivity.java in cordova for StatusBar color
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.os.Bundle; | |
import android.os.Build; | |
import android.util.Log; | |
import android.view.Window; | |
import android.graphics.Color; | |
if (Build.VERSION.SDK_INT >= 21) { | |
final Window window = this.getActivity().getWindow(); | |
window.clearFlags(0x04000000); // SDK 19: WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | |
window.addFlags(0x80000000); // SDK 21: WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
try { | |
// Using reflection makes sure any 5.0+ device will work without having to compile with SDK level 21 | |
window.getClass().getDeclaredMethod("setStatusBarColor", int.class).invoke(window, Color.parseColor("#000000")); | |
} catch (IllegalArgumentException ignore) { | |
Log.e(TAG, "Invalid hexString argument, use f.i. '#999999'"); | |
} catch (Exception ignore) { | |
// this should not happen, only in case Android removes this method in a version > 21 | |
Log.w(TAG, "Method window.setStatusBarColor not found for SDK level " + Build.VERSION.SDK_INT); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment