Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 单击文本视图时加载webview_Android_Android Webview - Fatal编程技术网

Android 单击文本视图时加载webview

Android 单击文本视图时加载webview,android,android-webview,Android,Android Webview,我想在安卓应用程序中单击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

我想在安卓应用程序中单击
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");
        }
    });

只需调用webView.loadUrl(“);textviewIs的单击事件我需要创建一个新的活动和xml布局页面来加载
webView
。在这里,我使用了相同的布局来加载webviewTry-then-intent.intent I=new-intent(intent.ACTION_视图);I.setData(Uri.parse(url));startActivity(I);谢谢大家支持我。我得到了
webview
。但是,它的格式不正确。它可能没有响应。你能帮我发布输出吗?我是指屏幕截图。看到我编辑的答案。你的答案帮助我加载了webview。所以我接受你的回答。解决了响应问题。请检查链接