简体   繁体   English

覆盖css文件中声明的android中的字体大小和背景色

[英]override font size and background color in android which is declared in css file

Hi all I am using webview in my application. 大家好,我在应用程序中使用的是webview。 I have css file which sets background color, font size. 我有一个css文件,它设置背景颜色,字体大小。 Now I want to set color and font size at runtime. 现在,我想在运行时设置颜色和字体大小。 How to override these properties at runtime in android? 如何在Android的运行时覆盖这些属性? I had tried like: 我曾尝试过像:

webview.setBackgroundColor(Color.parseColor("#919191"));
WebSettings webSettings = webView.getSettings();
webSettings.setDefaultFontSize(25);

But it does not work. 但这行不通。 I had also tried to written this code after webView.loadDataWithBaseURL(......) 我还尝试过在webView.loadDataWithBaseURL(......)之后编写此代码webView.loadDataWithBaseURL(......)

How to override font and bacground color at runtime? 如何在运行时覆盖字体和免费颜色?

The settings you mention are defaults. 您提到的设置是默认设置。 They are only applied if the page doesn't specify anything by itself. 仅当页面本身未指定任何内容时,才应用它们。

You can manipulate the text size at runtime by using WebSettings.setTextZoom ( doc ) or WebSettings.setMinimumFontSize ( doc ). 您可以通过使用WebSettings.setTextZoomdoc )或WebSettings.setMinimumFontSizedoc )在运行时操纵文本大小。

There is no API for manipulating background color of the page. 没有用于处理页面背景颜色的API。 The best you can do is running JavaScript code that will do that after the page has loaded. 最好的办法是运行JavaScript代码,该代码将在页面加载后执行。 For example: 例如:

webview.setWebViewClient(new WebViewClient() {
    @Override
    public void onPageFinished(WebView view, String url){
        view.loadUrl("javascript:document.body.style.backgroundColor = 'black';void(0);");
    }
});        

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM