为什么我无法在textView网址中获取该网址?非常感谢xP的帮助
public class Browser1Activity extends Activity {
TextView url;
WebView ourBrow;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
ourBrow = (WebView) findViewById(R.id.wvBrowser);
url = (TextView) findViewById(R.id.tvURL);
// cancel the web intent that default in android setting
ourBrow.setWebViewClient(new WebViewClient());
// webView seeting
ourBrow.getSettings().setJavaScriptEnabled(true);
ourBrow.getSettings().setLoadWithOverviewMode(true);
ourBrow.getSettings().setUseWideViewPort(true);
try {
ourBrow.loadUrl("https://www.google.com.au");
} catch (Exception e) {
e.printStackTrace();
}
url.setText(ourBrow.getUrl());
}
}
答案 0 :(得分:1)
TextView url = new TextView(this);
也许TextView的创建方式出了问题。
对于您的WebView,请尝试以下方法:
WebView ourBrow = (WebView) findViewById(R.id.wvBrowser);
ourBrow.setWebViewClient(new WebViewClient());
ourBrow.loadUrl("https://www.google.com/");
答案 1 :(得分:1)
您可以在页面完成或页面启动时随时获取Url
WebView web=new WebView(this);
web.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
// can get Here
view.getUrl();
//Now set to TExtView
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
// can get Here
view.getUrl();
//Now set to TExtView
}
});