[Solved] How to Add Prefix in WebView URL?


In the onClick() method of the button, just concatenate url and the query.

    @Override
    public void onClick(View view) {
        String url = urlEditText.getText().toString();
        String prefix = "https://www.google.com/search?q=";
        if(!url.startsWith("http://") && !url.startsWith("https://"))
        {
            url = prefix + url;
        }
        if(url.endsWith(".com") || url.endsWith(".as") || url.endsWith(".uk") || url.endsWith(".biz"))
        {
            if(!url.startsWith("http://") && !url.startsWith("https://"))
            {
                url = "http://" + url;
            }
        }
        if (validateUrl(url)) {
            webView.getSettings().setJavaScriptEnabled(true);
            webView.loadUrl(url);

            MainActivity.this.progress.setProgress(0);
        }
    }

14

solved How to Add Prefix in WebView URL?