Android设置Dialog对话框背景颜色圆角

这个设置背景圆角方法也适用于普通View。
 
 
ProgressDialog dialog = new ProgressDialog(mContext);
dialog.getWindow().setBackgroundDrawable(setDialogBack( 16, 16, 16, 16, 200, 195, 192, 192));
dialog.setMessage("Loading……");
dialog.setCanceledOnTouchOutside(false);
dialog.show();
 
 
 
 
 
 
/**
 *
 * @author
 * @Description: 圆角布局
 * @param cTopLeft
 *            布局左上角 圆角半径
 * @param cTopRight
 *            布局右上角 圆角半径
 * @param cBottomLeft
 *            布局左下角 圆角半径
 * @param cBottomRight
 *            布局右下角 圆角半径
 * @param a 背景颜色透明度
 * @param r RGB颜色值中的R值,可用16进制表示
 
 
 * @param g RGB颜色值中的G值,可用16进制表示
 
 
 * @param b RGB颜色值中的B值,可用16进制表示
*/
 
 
public Drawable setDialogBack(float cTopLeft, float cTopRight, float cBottomLeft,
                                                float cBottomRight, int a, int r, int g, int b) {
    float outRectr[] = new float[] { cTopLeft, cTopLeft, cTopRight, cTopRight, cBottomRight, cBottomRight, cBottomLeft, cBottomLeft };
    RoundRectShape rectShape = new RoundRectShape(outRectr, null, null);
    ShapeDrawable normalDrawable = new ShapeDrawable(rectShape);
    normalDrawable.getPaint().setColor(Color.argb(a, r, g, b));
    return normalDrawable;
}

猜你喜欢

转载自blog.csdn.net/peachs885090/article/details/78649292