改系统的dialog样式

AlertDialog dialog =   new AlertDialog.Builder(DownloadActivity.this)
        .setTitle("删除")
        .setMessage("确定要删除吗?")
        .setPositiveButton("是", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                String resu = cloudPhotoBeans.get(position).getPhotourl();

            }
        })
        .setNegativeButton("否", null)
        .create();


try {
    Field mAlert = AlertDialog.class.getDeclaredField("mAlert");
    mAlert.setAccessible(true);
    Object mAlertController = mAlert.get(dialog);
    Field mMessage = mAlertController.getClass().getDeclaredField("mMessageView");
    mMessage.setAccessible(true);
    TextView mMessageView = (TextView) mMessage.get(mAlertController);
    mMessageView.setTextColor(Color.parseColor("#292929"));
    mMessageView.setTextSize(15);
    Field mtitile = mAlertController.getClass().getDeclaredField("mTitleView");
    mtitile.setAccessible(true);
    TextView mTitleView = (TextView) mtitile.get(mAlertController);
    mTitleView.setTextSize(12);
    mTitleView.setTextColor(Color.parseColor("#626262"));
} catch (IllegalAccessException e) {
    e.printStackTrace();
} catch (NoSuchFieldException e) {
    e.printStackTrace();
}
dialog.show();
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(Color.parseColor("#000000"));
dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(Color.parseColor("#2785f1"));

你可能感兴趣的:(改系统的dialog样式)