Webview实现夜间模式,如果没有自己内核的话可以通过注入js实现 ,比较常用,但是对于显示图片效果就很差了.
还有一种方式, 在4.0原生的浏览器是有夜间模式这个功能的,他叫反色,但是这个函数是hide的,那么进行反射就可以了 可惜看了一下源码发现只有4.0以上才有
@Override
protected void onCreate(Bundle savedInstanceState) {
...
webview.loadUrl("http://en.wikipedia.org/wiki/Lena_S%C3%B6derberg");
try {
Class clsWebSettingsClassic =
getClassLoader().loadClass("android.webkit.WebSettingsClassic");
Method md = clsWebSettingsClassic.getMethod(
"setProperty", String.class, String.class);
md.invoke(webview.getSettings(), "inverted", "true");
md.invoke(webview.getSettings(), "inverted_contrast", "1");
} catch (Exception e) {}
}
The range of "inverted_contrast" is about 1 to 100 (not very sure).
http://i.imgur.com/IWsRcAW.png