我正在尝试从我的webview中的javascript界面开始一个活动.这个例子显示了一个祝酒词.我怎么能叫一个班而不是一个吐司呢?
public class JavaScriptInterface {
Context mContext;
/** Instantiate the interface and set the context */
JavaScriptInterface(Context c) {
mContext = c;
}
/** Show a toast from the web page */
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
}
Run Code Online (Sandbox Code Playgroud)
这对于html页面.
<input type="button" value="Say hello" onClick="showAndroidToast('Hello Android!')" />
<script type="text/javascript">
function showAndroidToast(toast) {
Android.showToast(toast);
}
Run Code Online (Sandbox Code Playgroud)