我收到包含html标签的api响应,我想用自定义字体样式将这些数据加载到webview中。任何人都可以告诉我如何将资源从资产加载到api响应数据。
对于所需的输出,我将第一个字符串替换为: -
replace("<p>", "<p style='font-family:Caecilia-Roman; src: url(file:///android_assets/fonts/pmn/Caecilia-Roman.otf)'><style> p:nth-child(1)::first-letter { color: #000; font-size: 40px; } p a{color: #dc3535;}</style>");
更新
String uu = "<p class='my-fonts'><style> @font-face {\n" +
" font-family: 'feast';\n" +
" src: url('fonts/pmn/Caecilia-Roman.otf');\n" +
"}\n" +
"\n" +
".my-fonts {font-family: 'feast';}p:nth-child(1)::first-letter { color: #000; font-size: 40px; } p a{color: #dc3535;}</style>Fusion GPS, a firm paid by Hillary Clinton’s campaign, was paying the wife of a senior Department of Justice official as part of its efforts to gather opposition research on Trump, and the official then brought that research to the FBI — raising the question of to what extent the firm may have been attempting to pay for heightened access to the criminal justice system, and whether they would have hired her absent her spousal connection.</p> <p style='font-family: Caecilia-Roman; src: url(file:///android_assets/fonts/pmn/Caecilia-Roman.otf)'><style> p:nth-child(1)::first-letter { color: #000; font-size: 40px; } p a{color: #dc3535;}</style>A declassified memo said Bruce “Ohr’s wife was employed by Fusion GPS to assist in the cultivation of opposition research on Trump. Ohr later provided the FBI with all of his wife’s opposition research, paid for by the DNC and Clinton campaign via Fusion GPS. The Ohrs’ relationship with Steele and Fusion GPS was inexplicably concealed from the” court when it was used to obtain a surveillance warrant.</p> <p style='font-family: Caecilia-Roman; src: url(file:///android_assets/fonts/pmn/Caecilia-Roman.otf)'><style> p:nth-child(1)::first-letter { color: #000; font-size: 40px; } p a{color: #dc3535;}</style>Bruce Ohr was deputy associate attorney general until December. House investigators determined that he met personally with Glenn Simpson, Fusion GPS’ founder.</p> <p style='font-family: Caecilia-Roman; src: url(file:///android_assets/fonts/pmn/Caecilia-Roman.otf)'><style> p:nth-child(1)::first-letter { color: #000; font-size: 40px; } p a{color: #dc3535;}</style>The FBI has limited resources to deal with a firehouse of information, so people seeking the FBI’s attention could potentially benefit from greasing the wheels in order to get info to the front of the queue and to a high level.</p> <p style='font-family: Caecilia-Roman; src: url(file:///android_assets/fonts/pmn/Caecilia-Roman.otf)'><style> p:nth-child(1)::first-letter { color: #000; font-size: 40px; } p a{color: #dc3535;}</style>“The money sweetened the pot for the Ohrs, and it certainly made it easier for Fusion to get the dossier to be used before the court if they made that payment to Bruce Ohr’s wife,” former judge and Texas GOP Rep. Louie Gohmert told The Daily Caller News Foundation,</p> <p style='font-family: Caecilia-Roman; src: url(file:///android_assets/fonts/pmn/Caecilia-Roman.otf)'><style> p:nth-child(1)::first-letter { color: #000; font-size: 40px; } p a{color: #dc3535;}</style>“Fusion had to have known that because of the relationship between Bruce Ohr and his wife, they were bringing Fusion, the DOJ and the DNC together under one roof to work for the same goal, which was to stop Donald Trump from becoming president,” he said.</p> <p style='font-family: Caecilia-Roman; src: url(file:///android_assets/fonts/pmn/Caecilia-Roman.otf)'><style> p:nth-child(1)::first-letter { color: #000; font-size: 40px; } p a{color: #dc3535;}</style>Ohr’s wife, Nellie, is a Russia expert, but it is not known what her specific contribution to the dossier was.</p> <p style='font-family: Caecilia-Roman; src: url(file:///android_assets/fonts/pmn/Caecilia-Roman.otf)'><style> p:nth-child(1)::first-letter { color: #000; font-size: 40px; } p a{color: #dc3535;}</style>“The financial arrangement between Mrs. Ohr and Fusion GPS gives the appearance of government-for-hire,” said Tom Anderson, an ethics expert at the conservative-leaning watchdog group the National Legal and Policy Center. It “appears to be a sophisticated scheme to get access to the highest levels of our government … ensuring the use of government resources in an attempt to influence an election.”</p> <p style='font-family: Caecilia-Rom";
mWebView.loadDataWithBaseURL("file:///android_assets/",uu,"text/html", "UTF-8", null);
我在资产文件夹中添加了字体。
已获得字符串格式,但未加载自定义字体。
这是我努力的尝试
谢谢。