我需要将HTML字符串设置到TextView中,但问题是<p style="text-align:center"><span style="font-family:montserrat"><span style="color:#660099"><strong>Hello World</strong></span></span></p>rn
font-family:montserrat
未应用于Text。
注意:我试图使用WebView加载此HTML字符串,但也出现了同样的问题。
请提出解决方法。感谢
将您的字体文件添加到您的android项目中,在您的情况下:montserrat.tff
在你的html字符串中这样定义:
@font-face { font-family: montserrat; src: url('fonts/montserrat.ttf'); }
然后这样尝试:
yourWebView.loadDataWithBaseURL("file:///android_asset/",htmlString,"text/html","utf-8",null);