티스토리 뷰

개발/개발 자료

웹뷰에서 alert 띄우기

시원한물냉 2014. 10. 11. 14:53
webView.setWebChromeClient(new webViewChromeClient());


/**
  * WebChromeClient 상속
  * */
 private class webViewChromeClient extends WebChromeClient {

  @Override
  public boolean onCreateWindow(WebView view, boolean dialog,
    boolean userGesture, Message resultMsg) {
   // TODO Auto-generated method stub
   return super.onCreateWindow(view, dialog, userGesture, resultMsg);
  }

  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  @Override
  public boolean onJsAlert(WebView view, String url, String message,
    final JsResult result) {

   // TODO Auto-generated method stub
   // return super.onJsAlert(view, url, message, result);
   new AlertDialog.Builder(view.getContext(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT)
     .setTitle("알림")
     .setMessage(message)
     .setPositiveButton(android.R.string.ok,
       new AlertDialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
         result.confirm();
        }
       }).setCancelable(false).create().show();
   return true;
  }

  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  @Override
  public boolean onJsConfirm(WebView view, String url, String message,
    final JsResult result) {
   // TODO Auto-generated method stub
   // return super.onJsConfirm(view, url, message, result);
   new AlertDialog.Builder(view.getContext(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT)
     .setTitle("알림")
     .setMessage(message)
     .setPositiveButton("예",
       new AlertDialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
         result.confirm();
        }
     })
     .setNegativeButton("아니오",
       new AlertDialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
         result.cancel();
        }
       }).setCancelable(false).create().show();
   return true;
  }
 }


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함