Skip to content

Instantly share code, notes, and snippets.

@hamzabasrai
Created August 20, 2021 13:24
Show Gist options
  • Save hamzabasrai/d9c2f290b8d9c4c467140ac82ef6c763 to your computer and use it in GitHub Desktop.
Save hamzabasrai/d9c2f290b8d9c4c467140ac82ef6c763 to your computer and use it in GitHub Desktop.
// Update webview theme
private void forceDarkMode(int mode) {
// This Dark Mode Strategy sets the css prefers-color-scheme property,
// instead of trying to automatically convert pages. (Consistent with iOS)
if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK_STRATEGY)) {
WebSettingsCompat.setForceDarkStrategy(this.bridge.getWebView().getSettings(), WebSettingsCompat.DARK_STRATEGY_WEB_THEME_DARKENING_ONLY);
}
if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
WebSettingsCompat.setForceDark(this.bridge.getWebView().getSettings(), mode);
}
}
// Update status bar and navigation bar theme
public void setLightNavigationBar(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
View view = getWindow().getDecorView();
int flags = view.getSystemUiVisibility();
flags &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
view.setSystemUiVisibility(flags);
Window window = getWindow();
window.setNavigationBarColor(ContextCompat.getColor(this, R.color.navigationBarColor));
}
}
public void setDarkNavigationBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
View view = getWindow().getDecorView();
int flags = view.getSystemUiVisibility();
flags |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
view.setSystemUiVisibility(flags);
Window window = getWindow();
window.setNavigationBarColor(ContextCompat.getColor(this, R.color.navigationBarColor));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment