Android has not been used for a long time, use it to pack a HTML5 game, the code is as follows
protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); WebView webview=new WebView (this); Webview.loadurl ("http://www.girl4493.cn/");//Add this sentence to the webview.setwebviewclient (new 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:
package activity.ysmall.cc.ysmall;import android.support.v7.app.actionbaractivity;import android.os.bundle;import android.view.menu;import android.view.menuitem;import android.webkit.webview;public class mainactivity extends actionbaractivity { @Override protected void oncreate (bundle savedinstancestate) { super.oncreate (savedInstanceState); webview webview=new webview (This); webview.getsettings (). Setjavascriptenabled (true);//Support js webview.loadurl ("http://www.girl4493.cn"); webview.setwebviewclient (New mywebviewclient ()); } @Override public booLean oncreateoptionsmenu (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; } @Override public boolean onoptionsitemselected ( Menuitem item) { // handle action bar item clicks here. The action bar will // automatically handle clicks on the home/up button, so long // as you specify a parent activity in&nbsP Androidmanifest.xml. int id = item.getitemid (); //noinspection SimplifiableIfStatement if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected (item); }}
With June
This article is from the "Yang Technical column" blog, please be sure to keep this source http://13438626.blog.51cto.com/13428626/1980441
JS Problem of Android using Web loading Web page