单击文本视图时加载网络视图

Load webview while clicking on a textview

我想在 Android 中从我的应用程序中单击 TextView 时加载 WebView。我应该怎么办?

我试过这个:

//Get a reference to your WebView//
WebView webView = (WebView) findViewById(R.id.webview);
webView.setVisibility(View.VISIBLE);
//Specify the URL you want to display// 
webView.loadUrl("https://example.com");

而 xml 代码是:

<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:visibility="gone"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

<TextView
    android:id="@+id/weblink"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:linksClickable="true"
    android:text="xxxxxxxxxxxxxxxxxxxx"
    android:textColor="@color/blue"
    android:textColorLink="@color/blue"
    />

但是无法正常工作。 id为"weblink"的TextView就是指定的TextView.

喜欢下面的代码:

WebView webView = (WebView) findViewById(R.id.webview);
TextView weblink=findElementById(R.id.weblink);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDisplayZoomControls(false);
    weblink.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            webView.setVisibility(View.VISIBLE);
            webView.loadUrl("https://example.com");
        }
    });