如何加载Web视图中dialoge在安卓视图、加载、Web、dialoge

2023-09-05 11:13:12 作者:骑着蜗牛追飞机

我试图加载Web视图中的对话框。我usuing以下code。

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)

设置web视图事后,像这样: 的WebView WV =(web视图)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>

您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());
            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();
        }
    });