My Android Learning experience 20

Source: Internet
Author: User

Use of WebView

WebView can be as intent as the interface jump, let the system browser open the page, you can also open the page in the application

Note When using WebView, you need to register the network service

The code is as follows:

Package com.example.webviewexample;

Import android.app.Activity;
Import android.media.audiofx.BassBoost.Settings;
Import Android.os.Bundle;
Import android.view.KeyEvent;
Import Android.view.Menu;
Import Android.view.MenuItem;
Import android.webkit.WebSettings;
Import Android.webkit.WebView;
Import android.webkit.WebViewClient;

Public class Mainactivity extends Activity {

private WebView WebView;
@Override
protected void onCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);

Init ();
}
private void Init () {
//TODO auto-generated method Stub
webview= (WebView) Findviewbyid (R.id.webview);
Webview.loadurl ("http://www.baidu.com");
//Overwrite system browser or third-party browser Open browser open
Webview.setwebviewclient (new Webviewclient () {

@Override
public boolean shouldoverrideurlloading (WebView view, String URL) {
TODO auto-generated Method Stub
When the return result is true, the Web page is opened in WebView, and if False, the system browser or third-party browser opens
View.loadurl ("http://www.baidu.com");
return true;
}

});
Enable support for loading the Javascripe scripting language
WebSettings settings=webview.getsettings ();
Settings.setjavascriptenabled (TRUE);
}
@Override
public boolean onKeyDown (int keycode, keyevent event) {
TODO auto-generated Method Stub
if (keycode==keyevent.keycode_back) {
if (Webview.cangoback ())
{
Webview.goback ();
return true;
}
else {
System.exit (0);
}
}
Return Super.onkeydown (KeyCode, event);
}
}

My Android Learning experience 20

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.