如何解决如何在 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>
previewer.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(例如带有一些简单的标题)。
然后尝试创建一个仅包含 webview 的新 xml 布局,参考 https://stackoverflow.com/a/50334176/8187800。
最后,如果问题仍然存在,您是否介意在这里分享一个基本的、最小的项目?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。