Reputation: 1317
To the code below using webView, is there any way to enter the site without typing the entire URL (www.google.com)? Currently need to enter the URL completely (http://www.google.com.br).
Code:
public class MainActivity extends ActionBarActivity {
private EditText editText;
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText) findViewById(R.id.url);
webView = (WebView) findViewById(R.id.webViewlayout);
webView.setWebViewClient(new MyBrowser());
}
public void abrirPagina (View v){
String url = editText.getText().toString();
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.loadUrl(url);
}
private class MyBrowser extends WebViewClient{
public boolean overrideUrlLoading (WebView view, String url){
view.loadUrl(url);
return true;
}
}
}
Upvotes: 0
Views: 60
Reputation: 1007484
You are welcome to examine url
and add additional information to it, through string concatenation, if needed. For example, you might see if it startsWith()
either http://
or https://
, then add http://
or https://
yourself if needed.
IOW, this is not the job of WebView
, but the job of the program handing the URL to WebView
.
Upvotes: 1