简体   繁体   English

如何使用javascript更改android webview的字体

[英]how to change font of android webView with javascript

first, i'm not a so familiar with javascript but i need to use it. 首先,我对javascript不太熟悉,但是我需要使用它。

what i need is to change the font of webView in android after loading web page, 我需要的是在加载网页后在android中更改webView的字体,

so in onPageFinished() i call the javascript code. 所以在onPageFinished()我调用了javascript代码。

i know this code can change the font: 我知道这段代码可以更改字体:

loadurl("javascript:(function(){document.body.style.fontFamily='\\"Courier New\\", Courier, monospace';})()");

it works fine and font get changed, but what i want is to apply my custom font from asset. 它工作正常并且字体得到更改,但是我要从资产应用我的自定义字体。

i tried something like this: 我尝试过这样的事情:

loadurl("javascript:(function(){document.body.style.fontFamily= \\"src: url('file:///android_asset/byekan.ttf')\\";})()");

and other things similar to this, without any success. 以及与此类似的其他事情,都没有成功。

so anyone can help me to apply my custom font after loading a page in android webview? 这样任何人都可以帮助我在android webview中加载页面后应用我的自定义字体?

note : the html is from an output source (it's not local) so i can not add any css style to it. 注意 :html来自输出源(它不是本地的),因此我无法向其添加任何CSS样式。

you can put below code in your html file 您可以将以下代码放在html文件中

<style>
        /** Specify a font named "MyFont",
            and specify the URL where it can be found: */
        @font-face {
          font-family: "MyFont";
          src: url('file:///android_asset/fonts/BLKCHCRY.TTF');
        }
        h3 { font-family:"MyFont"}  
</style>  

or later by "wv.loadUrl" set font for any element 或以后通过“ wv.loadUrl”为任何元素设置字体

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

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