Android 如何在wbeview中注入自定义css
我正在尝试在android应用程序中将自定义css添加到webview内容中,但它在webview中没有显示任何效果,可能是因为它尚未成功添加 我的自定义字体css:Android 如何在wbeview中注入自定义css,android,html,css,webview,android-webview,Android,Html,Css,Webview,Android Webview,我正在尝试在android应用程序中将自定义css添加到webview内容中,但它在webview中没有显示任何效果,可能是因为它尚未成功添加 我的自定义字体css: /* normal */ @font-face { font-family: 'PT_Sans-Web'; font-style: normal; font-weight: 400; src: local('PT_Sans Web Regular'), local('PT_Sans-Web-Regular'
/* normal */
@font-face {
font-family: 'PT_Sans-Web';
font-style: normal;
font-weight: 400;
src: local('PT_Sans Web Regular'), local('PT_Sans-Web-Regular'),url(file:///android_asset/fonts/PT_Sans-Web-Regular.ttf);
}
/* bold */
@font-face {
font-family: 'PT_Sans-Web';
font-style: normal;
font-weight: 700;
src: local('PT_Sans Web Bold'), local('PT_Sans-Web-Bold'), url(file:///android_asset/fonts/PT_Sans-Web-Bold.ttf);
}
style.css
body {
font-family: PT_Sans-Web;
color: #4DB2EC;
font-size: 15pt;
width: 100%;
background: #fff;
}
strong {
font-weight: bold;
}
embed,object,img{display: block; max-width:100%; height: auto;}
.frame {width: 100%}
#templates{display:none}
.subs-loading {width: 90%; margin: 2em auto; font-size: 1.5em; }
#subscriptions {
position: relative;
}
#container {
padding: 16px;
}
p {
font-family: PT_Sans-Web;
color: #4DB2EC;
font-size: 7pt;
width: 100%;
background: #fff;
line-height:11.38pt
}
h1 {
font-size: 2em;
line-height: 1.2em;
font-weight: bold;
color: #222;
margin: .1em 0 .2em;
}
正在webview中加载代码:
mWebView.loadDataWithBaseURL(
"file:///android_asset/",
content,
"text/html",
"utf-8",
null);
string content = "<!DOCTYPE html><html><head><meta charset='UTF-8' />"
+ "<meta name='viewport' content='width=device-width, initial-scale=1'>"
+ "<link rel='stylesheet' type='text/css' href='pt_sans.css'>"
+ "<link rel='stylesheet' type='text/css' href='webview.css'>"
+ "<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css\">"
+ "</head><body>"
+ mPostContent
+ "</body></html>";
测试设备nexus 5x并在其他设备上正常工作时出现此错误。将
css
文件放入assets
文件夹,然后在html
中对其进行寻址。更新内容
变量,如下所示:
string content = "<!DOCTYPE html><html><head><meta charset='UTF-8' />"
+ "<link rel=\"stylesheet\" href=\"file:///android_asset/style.css\">" //<-- Add this line
+ //...
string content=“”
+“”//它在安卓6的one plus测试设备上工作,但在安卓7版的nexus 5x中出现此错误“E/libEGL:validate_display:99 error 3008(EGL_BAD_display)”。我不知道该错误,但它显然与OpenGL有关,您无法控制。我认为你应该忽略它。
string content = "<!DOCTYPE html><html><head><meta charset='UTF-8' />"
+ "<link rel=\"stylesheet\" href=\"file:///android_asset/style.css\">" //<-- Add this line
+ //...