Загрузка веб-просмотра при нажатии на текстовое представление - PullRequest
0 голосов
/ 15 мая 2018

Я хочу загрузить WebView при нажатии на TextView из моего приложения в Android.Что я должен делать?

Я пробовал это:

//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"
    />

Но он не работает должным образом.TextView с идентификатором "weblink" является указанным TextView.

1 Ответ

0 голосов
/ 15 мая 2018

Сделайте, как показано ниже:

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");
        }
    });
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...