package com.example.helloworld; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.webkit.WebView; public class MainActivity extends Activity { private WebView webView = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); webView = (WebView)this.findViewById(R.id.webView); //设置字符集编码 webView.getSettings().setDefaultTextEncodingName("UTF-8"); //开启JavaScript支持 webView.getSettings().setJavaScriptEnabled(true); webView.addJavascriptInterface(this, "myObject"); //加载网页文件 String url = "http://*****/test.html"; webView.loadUrl(url); } public void changeActivity() { Intent intent = new Intent(); intent.setClass(MainActivity.this, ForwardTarget.class); startActivity(intent); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
<input type="button" value="跳转Activity" onclick="window.myObject.changeActivity();" />
其中:myObject是在JAVA中定义的名字,changeActivity是JAVA中定义的方法。