是的,我已经看过很多如何使用CSS使用自定义字体,但我不希望这样。我有一个带有WebView的应用程序,整个应用程序都有设备字体,但WebView具有WebViews的默认字体,看起来有点难看。
我可以使用以下命令获取默认的TypeFace:
Typeface.defaultFromStyle(R.style.YourTheme);
但是如何才能将其设置为WebView?或者以什么方式更好地获取当前设备的TypeFace并将其设置为WebView?感谢。
答案 0 :(得分:0)
如果您的HTML是本地的(在您的设备中),只需要像平常一样放置CSS文件和引用。
<title>Titulo de la web</title>
<link rel="stylesheet" href="estilo.css">
请记住将html文件和CSS放在资产目录中。
答案 1 :(得分:0)
我已经使用此代码在WebView上更改字体及其为我工作
data_webview = (WebView) findViewById(R.id.dataload_wv);
String custome_style = "<html><head><style type=\"text/css\">@font-face {font-family:
MyFont;src: url(\"file:///android_asset/font/roboto.ttf\")}body {font-family:
MyFont;font-size: medium;text-align: justify;}</style></head><body>";
String pass_data = "</body></html>";
String finalString = custome_style + YourTxext + pass_data;
data_webview.loadDataWithBaseURL(null,finalString, "text/html", "UTF-8", null);