Android using WebView

Source: Internet
Author: User

 Packagegzdewei.com.android;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.webkit.WebView;Importandroid.webkit.WebViewClient; Public classEjgrzactivityextendsActivity {/**Called when the activity is first created.*/    PrivateWebView WebView; @Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); //Setcontentview (R.layout.main); //Create a new web browserWebView =NewWebView ( This); //turn on JS supportWebview.getsettings (). setjavascriptenabled (true); //Web Adaptive Screen Switch//webview.getsettings (). Setusewideviewport (true);Webview.loadurl ("Http://xx.xx.com/login"); //StartWebview.setwebviewclient (Newwebviewclient () { Public Booleanshouldoverrideurlloading (WebView view, String URL) {view.loadurl (URL); return true;        }        });     Setcontentview (WebView); } @Override Public BooleanOncreateoptionsmenu (Menu menu) {menu.add (Menu.none, Menu.first+ 2, 1, "Back"). SetIcon (Android.                r.drawable.ic_media_previous); Menu.add (Menu.none, Menu.first+ 1, 2, "forward"). SetIcon (Android.                R.drawable.ic_media_next); Menu.add (Menu.none, Menu.first+ 3, 3, "Refresh"). SetIcon (Android.                R.drawable.ic_menu_directions); Menu.add (Menu.none, Menu.first+ 4, 4, "Exit"). SetIcon (Android.        R.drawable.ic_delete); return true; } @Override Public Booleanonoptionsitemselected (MenuItem item) {Switch(Item.getitemid ()) { CaseMenu.first + 2:            //Toast.maketext (This, "delete menu was clicked", Toast.length_long). Show ();Webview.goback ();  Break;  CaseMenu.first + 1:            //Toast.maketext (This, "delete menu was clicked", Toast.length_long). Show ();Webview.goforward ();  Break;  CaseMenu.first + 3: Webview.reload ();  Break;  CaseMenu.first + 4: Finish ();  Break; }        return false; } @Override Public voidonoptionsmenuclosed (Menu menu) {//Toast.maketext (This, "option menu off", Toast.length_long). Show ();} @Override Public BooleanOnprepareoptionsmenu (Menu menu) {//Toast.maketext (This, "The Options menu is displayed before the Onprepareoptionsmenu method is called, you can use this method to adjust the menu according to the prevailing situation", toast.length_long). Show (); //If you return False, this method will take the user to click on the menu action to consume, the Oncreateoptionsmenu method is not called        return true; } }

Android using WebView

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.