如何在android中的对话框中加载Web视图 [英] How to load web view in dialoge in android
问题描述
我正在尝试将 Web 视图加载到对话框中.我正在使用以下代码.
I am trying to load web view in to dialog. I am usuing the following code.
final TextView seeMonthlyBill = (TextView) parentLayout
.findViewById(R.id.my_ac_my_service_timewarnercable_link);
seeMonthlyBill.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Dialog dialog = new Dialog(getActivity());
WebView wb = new WebView(getActivity());
wb.getSettings().setJavaScriptEnabled(true);
wb.loadUrl("http://www.google.com");
wb.setWebViewClient(new HelloWebViewClient());
dialog.setCancelable(true);
dialog.setContentView(wb);
dialog.setTitle("WebView");
dialog.show();
}
});
我想在单击文本视图时打开网络视图.当我点击文本视图对话框时,没有 web 视图打开.任何人都可以帮我解决这个问题.
I want to open web view on the click on a text view. When i am clicking on the text view dialog is opening without the webview. Can any please help me to solve this issue.
提前致谢.
推荐答案
使用包含 Web 视图的 XML 布局.然后调用 dialog.setContentView(R.layout.web_dialog)
Use a XML layout containing a Webview. Then call dialog.setContentView(R.layout.web_dialog)
之后像这样设置webview:WebView wv = (WebView) findViewById(R.id.webview);R.id.webview"是 XML 布局文件中的 ID.
Set up the webview afterwards like so: WebView wv = (WebView) findViewById(R.id.webview); "R.id.webview" being the ID in the XML Layout file.
对话框布局示例:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<WebView
android:id="@+id/webview"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</LinearLayout>
您的代码已修改:
final TextView seeMonthlyBill = (TextView) parentLayout
.findViewById(R.id.my_ac_my_service_timewarnercable_link);
seeMonthlyBill.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Dialog dialog = new Dialog(getActivity());
dialog.setContentView(R.layout.web_dialog)
WebView wb = (WebView) dialog.findViewById(R.id.webview);
wb.getSettings().setJavaScriptEnabled(true);
wb.loadUrl("http://www.google.com");
wb.setWebViewClient(new HelloWebViewClient());
dialog.setCancelable(true);
dialog.setTitle("WebView");
dialog.show();
}
});
这篇关于如何在android中的对话框中加载Web视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!