Reputation:
I'm trying to apply rounded corners to my custom dialog. Dialog shows the rounded corners correctly but the outer space of corner is turned into white.
drawable/dialog_message_background
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="?postCardBackground"/> //light black color
<corners
android:radius="30dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
My layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:background="@drawable/dialog_message_background"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:background="@drawable/dialog_message_background"
android:orientation="vertical"
android:gravity="center"
android:layout_centerInParent="true"
android:layout_width="250dp"
android:layout_height="wrap_content">
<TextView
android:id="@+id/dialogMessageTv"
android:text="Error occured"
android:maxLines="3"
android:textStyle="bold"
android:textColor="?attr/postUserNameColor"
android:textSize="18sp"
android:layout_gravity="center"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ImageView
android:layout_marginTop="20dp"
android:id="@+id/messageDialogImg"
android:layout_width="70dp"
android:layout_height="70dp" />
<Button
android:id="@+id/messageDialogOkBtn"
android:layout_marginTop="20dp"
android:layout_marginBottom="5dp"
android:background="@drawable/dark_purple_btn_back"
android:text="ok"
android:textStyle="bold"
android:textSize="18sp"
android:textColor="@color/white"
android:layout_width="150dp"
android:layout_height="40dp" />
</LinearLayout>
</RelativeLayout>
Output window
Help me to remove the white color outside the custom dialog.
Upvotes: 1
Views: 1130
Reputation: 3
I have used this and it worked.
Add this in style.xml
:
<style name="RoundedCornersDialog" parent="@style/Theme.MaterialComponents.Dialog">
<item name="dialogCornerRadius">10dp</item>
</style>
and when creating dialog:
Dialog dialog=new Dialog(this,R.style.RoundedCornersDialog);
Upvotes: 0
Reputation: 31
in Java just make style for the dialog
<style name="RoundedCornersDialog" parent="@style/Theme.MaterialComponents.Dialog">
<item name="dialogCornerRadius">16dp</item>
</style>
and then assign it to the dialog
dialog = new Dialog(mContext,R.style.RoundedCornersDialog);
Upvotes: 1
Reputation: 364720
You don't need a shape to achieve a Dialog
with rounded corners.
You can override the getTheme()
method in your DialogFragment
:
import androidx.fragment.app.DialogFragment
class RoundedDialog: DialogFragment() {
override fun getTheme() = R.style.RoundedCornersDialog
//....
}
with:
<style name="RoundedCornersDialog" parent="@style/Theme.MaterialComponents.Dialog">
<item name="dialogCornerRadius">16dp</item>
</style>
In Java just use
public class RoundedDialog extends DialogFragment {
@Override
public int getTheme() {
return R.style.RoundedCornersDialog;
}
}
Upvotes: 1