Android
2018.09.23 / 16:18

[android] AlertDialog - You need to use a Theme.AppCompat theme (or descendant) with this activity.

hangawee
Ãßõ ¼ö 197

MainActivity¿¡¼­ Context¸¦ ¼±¾ðÇÏ°í

 

private Context mContext;

 

onCreate¾È¿¡¼­ applicationContext¸¦ ¹Þ¾Æ¼­

mContext=this.getApplicationContext();

 

 

º°µµÀÇ Å¬·¡½º·Î ¼±¾ðÇÑ WebChromeClient¿¡¼­ »ç¿ëÇÏ·Á°í ÇÏ´Ï

 

¹ØÁÙÄ£ ºÎºÐ¿¡¼­ You need to use a Theme.AppCompat theme (or descendant) with this activity. ¿¡·¯°¡ ¹ß»ýÇÑ´Ù.

class UriChromeClient extends WebChromeClient {

@Override
public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result)
{
new AlertDialog.Builder(mContext).setTitle("AlertDialog").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;
}
}

-> ÇØ°á¹æ¹ý À§ ÄÚµåÀÇ mContext¸¦ MainActivity.this ·Î ¹Ù²ãÁØ´Ù.

class UriChromeClient extends WebChromeClient {

@Override
public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result)
{
new AlertDialog.Builder(MainActivity.this).setTitle("AlertDialog").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;
}
}