Android has not been used for a long time, use it to pack a HTML5 game, the code is as follows
OnCreate (Bundle savedinstancestate) { Super. OnCreate (savedinstancestate); WebView webview=WebView (this); Webview.loadurl ("http://www.mimi199.com/");
Plus this sentence will be able to webview.setwebviewclient (Mywebviewclient ()); }
Use when found that all JS can not be used to find a half-day finally know where the problem, using WebView default is the JS off, so it will not execute the JS code, this time only need to add a word to suffice
Webview.getsettings (). setjavascriptenabled (true); //Support JS
Yes, this sentence is enough, true indicates that the support JS false means that does not support JS, default is not supported, the pattern AH
The complete code is as follows:
PackageActivity.ysmall.cc.ysmall;Importandroid.support.v7.app.ActionBarActivity;ImportAndroid.os.Bundle;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.webkit.WebView;Public classMainactivityextendsactionbaractivity {@Overrideprotected voidOnCreate (Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); WebView webview=NewWebView ( This); Webview.getsettings (). setjavascriptenabled (true);//Support JSWebview.loadurl ("http://www.mimi199.com/"); Webview.setwebviewclient (NewMywebviewclient ()); } @OverridePublic BooleanOncreateoptionsmenu (Menu menu) {//inflate the menu; This adds items to the action bar if it is present.Getmenuinflater (). Inflate (R.menu.Menu_main, menu);return True; } @OverridePublic BooleanOnoptionsitemselected (MenuItem Item) {//Handle Action Bar item clicks here. The Action Bar would//automatically handle clicks on the Home/up button, so long//As you specify a parent activity in Androidmanifest.xml.intid = item.getitemid ();//noinspection simplifiableifstatementif(id = = R.id.action_settings) {return True; }return Super. onoptionsitemselected (item); }}
With June
JS Problem of Android using Web loading Web page