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。所以我接受你的回答。解决了响应问题。请检查链接