Issue
I want to load a WebView
while clicking on a TextView
from my app in Android. What should I do?
I have tried this one:
//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");
And the xml code is:
<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"
/>
But it is not working properly. The TextView
with id "weblink" is the specified TextView
.
Solution
Do like the below code :
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");
}
});
Answered By - Koustuv Ganguly
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.