如何通过单击ImageButton在androdi中打开WebView?

时间:2017-09-10 10:51:47

标签: android

    android:layout_width="368dp"
    android:layout_height="495dp"
    android:orientation="vertical"
    tools:layout_editor_absoluteY="8dp"
    tools:layout_editor_absoluteX="8dp">

    <WebView
        android:id="@+id/webView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:visibility="invisible" />

    <ImageButton
        android:id="@+id/imgButton"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginBottom="30dp"
        android:layout_marginLeft="140dp"
        android:onClick="loadUrl"
        android:src="@drawable/img"
        android:contentDescription="@null"/>

</LinearLayout>

如何在不打开任何浏览器的情况下点击ImageButton或ImageView在我的应用中打开网站?

2 个答案:

答案 0 :(得分:0)

        public void loadUrl(View view) {
                View rootView = view.getParent();
                wv =(WebView) rootView.findViewById(R.id.web_page);
                wv.setVisibility(View.VISIBLE);

                wv.setWebViewClient(new WebViewClient());

                wv.loadUrl("http\\and.so.on");
        }

答案 1 :(得分:0)

public void loadUrl(View view) {
    webView = findViewById(R.id.webView);
    webView.getSettings.setJavaScriptEnabled(true);
    webView.setChromeClient(new ChromeClient());
    webView.setWebViewClient(new WebViewClient());
    webView.loadUrl("Whatever you want to load");
}