android - 如何用 WebView 填充 AlertDialog?
问题描述
我有一个全屏 AlertDialog 在 webview 中加载一个 html 文件。我希望 html 内容填充 AlertDialog,从而填充屏幕(如果它有边框没问题,但如果没有边框会很好)。
AlertDialog 正确地填满了屏幕,但是 webview 只出现在屏幕的顶部,下面有很多空间。奇怪的是,webview 填充了宽度,但没有填充高度。看:
如何强制 webview 填充 AlertDialog?
这是我的代码:
WebView myMsg = new WebView(context);
myMsg.getSettings().setJavaScriptEnabled(js);
myMsg.setVerticalScrollBarEnabled(overflow);
myMsg.setHorizontalScrollBarEnabled(overflow);
myMsg.getSettings().setAllowContentAccess(true);
myMsg.getSettings().setAllowFileAccess(true);
myMsg.getSettings().setLoadWithOverviewMode(true);
myMsg.getSettings().setUseWideViewPort(true);
myMsg.getSettings().setBuiltInZoomControls(true);
myMsg.getSettings().setDisplayZoomControls(false);
myMsg.setInitialScale(1);
myMsg.setWebViewClient(new WebViewClient() {
@Override
// Prevents exposing the URI in API>26 !
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
myMsg.loadUrl(page);
myMsg.setBackgroundColor(0);
myMsg.setSoundEffectsEnabled(true);
AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setView(myMsg)
.setIcon(R.drawable.ic_launcher);
final AlertDialog dialog = builder.create();
Window dialogWin = dialog.getWindow();
dialog.show();
if (dialogWin != null) {
dialogWin.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialogWin.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
dialogWin.setFlags(android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN,
android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
解决方案
推荐阅读
- c++ - 构建解决方案时如何解决 Visual Studio 2019 'invalid profile ms_6_5' 错误?
- r - 纯粹在基础 R 中的管道(“基础管道”)?
- erlang - 为什么 Dialyzer 相信具有过于具体的返回类型的规范?
- r - R - 如何在 Dplyr Summarize 函数中删除缺失值和 Nan?
- vue.js - 如何使用计算过滤json对象中的数组
- django - 如何在 django 中显示 glyphicon-plus?
- sql - 如何将从列确定的小时数添加到时间戳列?
- python - 根据列值更改散点图标记的大小 - Python 3.6.x
- assembly - 如何从 Bios 数据区的地址中正确读取值?
- html - 辅助功能:“下载文件”对话框在 IE 中未激活