I have created a custom AlertDialog with rounded corners using onDraw
of LinearLayout
as below,
public class RoundedLinearLayout extends LinearLayout {
private Paint drawPaint;
private Paint roundPaint;
private int mCornerRadius = 100;
private RectF bounds;
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public RoundedLinearLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
onInit();
}
public RoundedLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
onInit();
}
public RoundedLinearLayout(Context context) {
super(context);
onInit();
}
protected void onInit() {
drawPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
drawPaint.setColor(0xffffffff);
drawPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
roundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
roundPaint.setColor(0xffffffff);
setWillNotDraw(false);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
if (w != oldw && h != oldh) {
bounds = new RectF(0, 0, w, h);
}
}
@Override
protected void dispatchDraw(Canvas canvas) {
Bitmap bitmap = Bitmap.createBitmap((int) bounds.width(), (int) bounds.height(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bitmap);
super.dispatchDraw(c);
BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(shader);
canvas.drawRoundRect(bounds, mCornerRadius, mCornerRadius, paint);
}
}
And then I added transparency by getWindow()
and setting window.alpha = 0.5f
.
The resulting dialog is,
I want to remove those corner white background. I have searched 100s of questions here and no answer could get me the perfect rounded corner alert dialog. Any help would be appreciated!
This worked for me
background verification is my drawable file
This can be solved:
I use this and it worked for me:
ConfirmacionMensaje exntends from Dialog
and this is my xml for Dialog:
are you sure you want to use a dialog? it seems more like a temporary popup, like a toast or a crouton:
about the background, you could use one with 9-patch or a custom xml drawable (example here and here) ...
this is worked for me,for the first time
here i am getting the resource from drawable folder,background_verification is drawable file
create xml in drawable folder with dialog_corner.
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="@color/main_background"/> <corners android:topLeftRadius="@dimen/margin_10" android:topRightRadius="@dimen/margin_10" android:bottomRightRadius="@dimen/margin_10" android:bottomLeftRadius="@dimen/margin_10" /> </shape>
2.put in layout
android:background="@drawable/dialog_corner"
3.in you java file keep below code