如何在WebView中打开字符串(URL) [英] How to open string(url) in WebView
本文介绍了如何在WebView中打开字符串(URL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从EditField中打开一个字符串,然后按按钮,页面应该在我的WebView中打开.默认情况下,不是通过我的网址打开网络浏览器
I would like to open a string from EditField, and by pressing button, the page should open in my WebView. Instead of my url is opening by default web browser
XML:
代码:
public class WebAdress extends Activity {
WebView webView;
ImageButton buttonGo;
EditText textWWW;
String URL = new String();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.www);
buttonGo = (ImageButton) findViewById(R.id.imageButton1);
textWWW = (EditText) findViewById(R.id.editText1);
webView = (WebView) findViewById(R.id.webView1);
buttonGo.setOnClickListener(new OnClickListener() {
@SuppressLint("SetJavaScriptEnabled")
public void onClick(View v) {
URL = "http://" + textWWW.getText().toString();
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
webView.loadUrl(URL);
URL = null;
}
});
}
}
推荐答案
首先检查清单文件以检查Internet权限,然后尝试使用此代码将url加载到webview中.他的代码对我也有相同的看法.
first check your menifest file to check internet permission and then try this code to load url in to webview. his code works for me for the same view.
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl(YOUR ANY URL);
webview.setWebViewClient(new webviewClient());
class webviewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
希望它会对您有所帮助.
Hope it will help you.
这篇关于如何在WebView中打开字符串(URL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文