我试图在我的应用程序 WebView 中显示一个 iframe,但我遇到了无法使用 CSS 'overflow:hidden;' 切断 iframe 底部 30 像素的问题。我解决这个问题的方法是制作我自己的 index.html 文件并将其作为资产保存在我的应用程序中。
如果您的项目中没有“资产”文件夹,请转到第 1 步
(这与“res”文件夹不同)
[在 Windows 7 上]
第 1 步 - 创建 assets 文件夹:在您的 Android Studio 项目中点击:
文件 --> 新建 --> 文件夹 --> 资产文件夹
Image showing how to make assets folder in Windows
第 2 步 - 将 index.html 用于在 <div> 中保存您的 <iframes>
您可以复制以下代码以用作 index.html 文件中的示例代码:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
</head>
<body style="margin:0px;">
<div style="width:605px;height:875px;overflow:hidden;">
<iframe src="https://docs.google.com/presentation/d/1QyNNURCVBme50SAuIceq3sh7Ky74LuWNeEM8B910aC4/embed?start=true&loop=true&delayms=2000" scrolling="no" frameborder="0" width="605" height="905" allowfullscreen="false" mozallowfullscreen="false" webkitallowfullscreen="false"></iframe>
</div>
</body>
</html>
第 3 步 - 在您的 WebView 中调用 index.html 文件
注意--(此示例 WebView 的 ID 为“main_ad”,将此 id 更改为您命名的 webview id)
WebView webView = (WebView) findViewById(R.id.main_ad);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("file:///android_asset/index.html"); //this is why you needed the assets folder
webView.getSettings().setJavaScriptEnabled(true);
希望这甚至可以帮助 1 个人使用 webviews 和 iframe