Tôi đang cố bắt đầu một hoạt động từ giao diện javascript trong chế độ xem web của mình. Ví dụ cho thấy bánh mì nướng. Làm thế nào tôi có thể gọi một lớp thay vì một bánh mì nướng?sử dụng javascript trong webview android
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();
}
}
trang này cho trang html.
<input type="button" value="Say hello" onClick="showAndroidToast('Hello Android!')" />
<script type="text/javascript">
function showAndroidToast(toast) {
Android.showToast(toast);
}
Tôi không đủ kinh nghiệm để trả lời nhưng bạn đã đọc điều này chưa: http://developer.android.com/guide/webapps/webview.html#UsingJavaScript – JaredMcAteer
tôi đã làm điều đó. – Common
Ok Tôi chỉ không thấy bất kỳ nơi nào bạn đã bật javascript trong chế độ xem web và mặc dù nó có liên quan. – JaredMcAteer