Android WebView未在自定义对话框布局内加载
我试图将pdf文档从web加载到url(我在浏览器中访问了该文档,并且工作正常),但在自定义Android WebView未在自定义对话框布局内加载,android,webview,android-alertdialog,Android,Webview,Android Alertdialog,我试图将pdf文档从web加载到url(我在浏览器中访问了该文档,并且工作正常),但在自定义AlertDialog中的WebView中加载url时,我的WebView没有显示任何内容 警报对话框\u webview.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:ori
AlertDialog
中的WebView中加载url时,我的WebView没有显示任何内容
警报对话框\u webview.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingStart="10dp"
android:paddingRight="10dp"
android:paddingEnd="10dp"
>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/web_view"
></WebView>
</RelativeLayout>
安卓
Webview
不支持PDF
,尽管chrome应用程序支持它
但是,如果您想在应用程序中打开PDF
,您可以使用
如果仍要在Webview
中打开PDF,可以使用google drive的url打开PDF文件
但是,它就像一个打开pdf的网页,上面有谷歌工具栏。
检查此答案以实现以下目标:-
Android
Webview
不支持PDF
,尽管chrome应用程序支持它
但是,如果您想在应用程序中打开PDF
,您可以使用
如果仍要在Webview
中打开PDF,可以使用google drive的url打开PDF文件
但是,它就像一个打开pdf的网页,上面有谷歌工具栏。
检查此答案以实现以下目标:-
试试这个:)
试试这个:)
我对
AlertDialog
中的WebView
也有同样的问题,但我注意到WebView
正在加载url,但其高度非常小,因此很难知道是否加载了de page
我发现的诀窍是,您需要在WebView中添加一个weight
属性,并在height
中使用match\u parent
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<WebView
android:id="@+id/webview_terms"
android:layout_width="match_parent"
android:layout_height="match_parent" <!-- use match_parent -->
android:layout_weight="1" <!-- add this line -->
tools:ignore="InefficientWeight" />
<Button
android:id="@+id/btn_accept_terms"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:background="@drawable/background_button_selector"
android:text="@string/accept_button"
android:textColor="@android:color/white" />
</LinearLayout>
android:layout_weight=“1”
工具:忽略=“无效权重”/
我对AlertDialog
中的网络视图
也有同样的问题,但我注意到网络视图
正在加载url,但其高度非常小,因此很难知道是否加载了de页面
我发现的诀窍是,您需要在WebView中添加一个weight
属性,并在height
中使用match\u parent
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<WebView
android:id="@+id/webview_terms"
android:layout_width="match_parent"
android:layout_height="match_parent" <!-- use match_parent -->
android:layout_weight="1" <!-- add this line -->
tools:ignore="InefficientWeight" />
<Button
android:id="@+id/btn_accept_terms"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:background="@drawable/background_button_selector"
android:text="@string/accept_button"
android:textColor="@android:color/white" />
</LinearLayout>
android:layout_weight=“1”
工具:忽略=“无效权重”/
为什么要执行对话框.setView(视图)代码>两次?您可能想从webview.loadUrl(url)中删除注释
@V-rundPuro-hit如果我正在设置webViewClient
您的webview如何知道要加载哪个url?如果您正在设置webViewClient
,但您没有将加载url传递给它,则可以。为什么要执行dialog.setView(view)代码>两次?您可能想从webview.loadUrl(url)中删除注释
@V-rundPuro-hit如果我正在设置webViewClient
您的webview如何知道要加载哪个url?如果您正在设置webViewClient
,但您没有传递加载到它的url,您可以在WebView
中加载PDF,这是一个解决方法使用google drive的预url,您可以,但它就像一个打开PDF.Yah的网页。但仍然可以在其中加载pdf。因此,说Webview不支持PDFpre是错误的,因为添加驱动器url已奏效,但仍然无法理解为什么Webview不支持直接加载文档Webview不支持直接加载PDF,这与直接支持PDF的IOS Webview不同。您可以在Webview
中加载PDF,使用google drive的预url,你可以,但它就像一个网页打开pdf.Yah。但仍然可以在其中加载pdf。因此,说Webview不支持PDFpre的说法是错误的,因为添加驱动器url已奏效,但仍然无法理解为什么Webview不支持直接加载文档。Webview不直接支持PDF,这与直接支持PDF的IOS Webview不同。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<WebView
android:id="@+id/webview_terms"
android:layout_width="match_parent"
android:layout_height="match_parent" <!-- use match_parent -->
android:layout_weight="1" <!-- add this line -->
tools:ignore="InefficientWeight" />
<Button
android:id="@+id/btn_accept_terms"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:background="@drawable/background_button_selector"
android:text="@string/accept_button"
android:textColor="@android:color/white" />
</LinearLayout>