android - 如何修复在 Xamarin.Android 中始终为零的 AlertDialog(全屏)内的 WebView 中的高度?
问题描述
我一直在尝试在AlertDialog.Builder
. 过了一会儿,我发现主要问题是它没有高度,因为正在加载网站:
它的外观:
添加高度后的外观:
这些是我的 XML:
webview_fulscreen.xml
<?xml version="1.0" encoding="UTF-8" ?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/frameFull"
android:orientation="vertical">
<include layout="@layout/previewer" />
<ImageView
android:layout_width="@dimen/close_dialog"
android:layout_height="@dimen/close_dialog"
android:src="@drawable/ic_close_black_48dp"
android:clickable="true"
android:layout_gravity="left"
android:layout_marginTop="@dimen/close_dialog_margin_top"
android:layout_marginLeft="@dimen/close_dialog_margin_left"
android:tint="@color/colorLblBnd"
android:id="@+id/previewClose"
/>
</FrameLayout>
预览器.xml
<?xml version="1.0" encoding="UTF-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ProgressBar
android:id="@+id/indeterminateBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:indeterminate="true"
android:max="100"
android:layout_height="wrap_content"
/>
<android.webkit.WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webView" />
</LinearLayout>
这就是我调用 AlertDialog 的方式:
string videoUrl = "file:///android_asset/website/video.html";
View dialogView = LayoutInflater.From(view.Context).Inflate(Resource.Layout.webview_fullscreen, null);
var webView = dialogView.FindViewById<WebView>(Resource.Id.webView);
var imageView = dialogView.FindViewById<ImageView>(Resource.Id.previewClose);
var pBar = dialogView.FindViewById<ProgressBar>(Resource.Id.indeterminateBar);
webView.SetWebChromeClient(new WebChromeClient());
webView.Settings.JavaScriptEnabled = true;
webView.Settings.AllowFileAccessFromFileURLs = true;
webView.Settings.DomStorageEnabled = true;
webView.LoadUrl(videoUrl);
using var dialogBuilder = new AlertDialog.Builder(view.Context, Android.Resource.Style.ThemeMaterialLightNoActionBarFullscreen);
dialogBuilder.SetView(dialogView);
dialogBuilder.Show();
我尝试通过脚本设置高度,但没有成功。知道如何获得高度或计算吗?另外,我尝试以RelativeLayout
编程方式设置,但它也不起作用。
解决方案
首先,尝试在 AlertDialog 中加载一个简单的静态 html(例如,带有一些简单的标题)。
然后尝试创建一个新的xml布局,里面只有一个webview,参考https://stackoverflow.com/a/50334176/8187800。
最后,如果问题仍然存在,您介意在这里分享一个基本的、最小的项目吗?
推荐阅读
- blazor - 为什么不改变变量的值
- pycharm - 现在强制 lsyncd 到 sybc
- google-cloud-platform - 有什么方法可以从 Windows 中的 powershell 打开 google cloud shell
- c++ - UE4 - 如何在给定 4 个屏幕坐标的情况下缩放纹理或材质?
- spring-integration - Spring 集成 Java DSL 示例
- swift - 如何将变量声明为 Equatable?
- typescript - 如何根据传递的类判断构造函数的类型?
- python - “需要一个类似字节的对象,而不是 str”Python 中的错误
- python - Python 3 中的内部类中的超级
- swift - 如何快速在属性包装器结构中实现属性观察器?