web对话框


分享一个自用的web对话框

public class WebDialog extends AlertDialog.Builder {
private AlertDialog mDialog;
private AppCompatCheckBox check;
private  WebView webView;
public WebDialog(Context context,String title,String ss,String key) {
    super(context);
    initWebDialog(context,title,ss,key);
}
private void initWebDialog(final Context context , String title,String ss, final String key) {
    View welmsg = View.inflate(context,R.layout.dialog_webview, null);
    check = (AppCompatCheckBox) welmsg.findViewById(R.id.check_ok);
    setView(welmsg);
    setTitle(title);
    webView = (WebView) welmsg.findViewById(R.id.webview);
    webView.loadUrl(ss);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setAllowFileAccess(true);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setDatabaseEnabled(false);
    webView.getSettings().setDefaultTextEncodingName("UTF-8");
    webView.setWebChromeClient(new WebChromeClient());
    webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
    webView.getSettings().setSupportMultipleWindows(true);
    setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            String checkBoxResult = "NOT checked";
            if (check.isChecked())  checkBoxResult = "checked";
            SharedPreferences settings = context.getSharedPreferences(key, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString("skipMessage", checkBoxResult);
            editor.commit();
            return;
        }

    });

    SharedPreferences settings = context.getSharedPreferences(key, 0);
    String skipMessage = settings.getString("skipMessage", "NOT checked");
    mDialog = create();
    //mDialog.show();
    mDialog.getWindow().setBackgroundDrawableResource(R.drawable.dialog_bg);
    mDialog.setCanceledOnTouchOutside(false);
    if (!skipMessage.equalsIgnoreCase("checked") ) mDialog.show();
    if (!skipMessage.equalsIgnoreCase("checked") )mDialog.setCancelable(false);
}}

使用方法:

WebDialog(mContext, “对话框标题”, "URL", "KEY")

声明:本网站采用BY-NC-SA协议进行授权

版权:LeoROM丨FusionLeo内核丨三星S9丨三星S8|版权所有,违者必究|如未注明,均为原创

转载:转载请注明原文链接 - web对话框


不忘初心 方得始终