url 未在对话框内的 WebView 中显示
url not showing in WebView inside a Dialog
我正在尝试在 WebView
中打开此 url 对话框:http://mtl2.liveatc.net/eham01_rdr_artip
但什么也没发生(其他 url 一切正常)。我只看到该应用正在加载页面,完成后对话框消失。
这是我的代码:
Dialog dialog = new Dialog(AtcInfo.this);
dialog.setContentView(R.layout.web_dialog);
WebView wb = dialog.findViewById(R.id.webview);
wb.getSettings().setJavaScriptEnabled(true);
wb.loadUrl(listUrl.get(position));
wb.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
pBar.setVisibility(View.INVISIBLE);
super.onPageFinished(view, url);
}
});
dialog.setCancelable(true);
dialog.show();
还有 web_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<WebView
android:id="@+id/webview"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
我试图调整大小 WebView
,但没有任何效果。我将不胜感激任何帮助或提示。
为您的 ScrollView
设置固定的高度和宽度,并在您的 WebView
中添加 android:layout_weight="1"
作为额外属性。我认为这应该符合您的目的。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroller"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_gravity="center"
android:fillViewport="true">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbars="vertical" />
</ScrollView>
在我的模拟器中看起来像这样。
我正在尝试在 WebView
中打开此 url 对话框:http://mtl2.liveatc.net/eham01_rdr_artip
但什么也没发生(其他 url 一切正常)。我只看到该应用正在加载页面,完成后对话框消失。
这是我的代码:
Dialog dialog = new Dialog(AtcInfo.this);
dialog.setContentView(R.layout.web_dialog);
WebView wb = dialog.findViewById(R.id.webview);
wb.getSettings().setJavaScriptEnabled(true);
wb.loadUrl(listUrl.get(position));
wb.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
pBar.setVisibility(View.INVISIBLE);
super.onPageFinished(view, url);
}
});
dialog.setCancelable(true);
dialog.show();
还有 web_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<WebView
android:id="@+id/webview"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
我试图调整大小 WebView
,但没有任何效果。我将不胜感激任何帮助或提示。
为您的 ScrollView
设置固定的高度和宽度,并在您的 WebView
中添加 android:layout_weight="1"
作为额外属性。我认为这应该符合您的目的。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroller"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_gravity="center"
android:fillViewport="true">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbars="vertical" />
</ScrollView>
在我的模拟器中看起来像这样。