最近公司使用android打包html5游戏,
使用android点webview打包html5游戏,代码都好了,具体如下
public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
WebView webView=new WebView(this);
webView.getSettings().setJavaScriptEnabled(true);//支持js webView.loadUrl("http://www.ysmall.cc/mobile");
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 AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true;
} return super.onOptionsItemSelected(item);
}
}
一切貌似很完美,玩游戏,被电脑打败了(我真菜!!!),游戏提示失败,点击“更多游戏”去查看其他游戏,点进去后,然后点返回键,问题来了,不是挖掘技术哪家强,是webview没有后退功能,没法退回首页,而是直接退出,android开发问题还真多啊,还好哥机灵,找资料呗!
终于找到问题了,
只需要重写activity的onKeyDown方法,在onKeyDown里后退即可
全部代码贴出,免得以后忘记
bingo
与君共勉~
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。