发布网友 发布时间:2022-04-22 02:51
共1个回答
热心网友 时间:2023-09-01 06:44
1、代码:
Wv.getSettings().setLightTouchEnabled(true);
Wv.getSettings().setJavaScriptEnabled(true);
Wv.addJavascriptInterface(myJavaScriptInterface, "AndroidFunction");
public class JavaScriptInterface {
Context mContext;
JavaScriptInterface(Context c) {
mContext = c;
}
public void showToast(String webMessage){
final String msgeToast = webMessage;
myHandler.post(new Runnable() {
@Override
public void run() {
// This gets executed on the UI thread so it can safely modify Views
myTextView.setText(msgeToast);
}
});
Toast.makeText(mContext, webMessage, Toast.LENGTH_SHORT).show();
}
}
2、js中调用
AndroidFunction.showToast(testVal);