0

我有一个这样的 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"  android:background="#262626">

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="EXIT" />

 <ScrollView
        android:id="@+id/sv2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginTop="10dp" android:background="#ffffff">

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <WebView
                android:id="@+id/add_webView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:scrollbarStyle="insideOverlay"
                android:text="@string/desc" />

        </RelativeLayout>
    </ScrollView>
</LinearLayout>

我想在我的应用程序中加载我的 Url,并保留我在 webView 上方创建的按钮。不幸的是,我在设备浏览器的新窗口中获得了 webView。

这就是我调用 webView 的方式:

WebView add_webView = (WebView) dialog
                    .findViewById(R.id.add_webView);

            add_webView.loadUrl(MYLINK);

如何让我的 webView 进入我的应用程序而不是浏览器窗口?谢谢!!:)

4

1 回答 1

0

正如我希望在对话框中使用 webView,解决方案是使用 setWebClient()

AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setTitle("Title here");
    WebView wv = new WebView(this);

    wv.loadUrl("http:\\www.google.com");

    wv.setWebViewClient(new WebViewClient()
    {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url)
        {
            view.loadUrl(url);

            return true;
        }
    });

    alert.setView(wv);
    alert.setNegativeButton("Close", new DialogInterface.OnClickListener()
    {
        @Override
        public void onClick(DialogInterface dialog, int id)
        {
        }
    });
    alert.show();
于 2013-04-15T19:04:57.867 回答