android 浏览器夜间模式

本文介绍了如何在Android浏览器中实现夜间模式,通过WebView加载特定JS代码,动态修改HTML页面元素颜色,以达到夜间阅读友好效果。
摘要由CSDN通过智能技术生成

      在浏览器中有需要设置为夜间模式的功能,主要实现为webView加载一段js代码到对应的url中,这段js会动态的修改html页面的各个标签的颜色,达到夜间模式的效果。加载的js代码如下

javascript: (function() {
  
    css = document.createElement('link');
    css.id = 'xxx_browser_2014';
    css.rel = 'stylesheet';
    css.href = 'data:text/css,html,body,header,div,a,span,table,tr,td,th,tbody,p,form,input,ul,ol,li,dl,dt,dd,section,footer,nav,h1,h2,h3,h4,h5,h6,em,pre{background: #333 !important;color:#616161!important;border-color:#454530!important;text-shadow:0!important;-webkit-text-fill-color : none!important;}html a,html a *{color:#5a8498!important;text-decoration:underline!important;}html a:visited,html a:visited *,html a:active,html a:active *{color:#505f64!important;}html a:hover,html a:hover *{color:#cef!important;}html input,html select,html button,html textarea{background:#4d4c40!important;border:1px solid #5c5a46!important;border-top-color:#
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值