I am trying to load a custom view of my dialog in my activity. I want to remove the white space to the right of the dialog.
My activity
public class MyActivity extends AppCompatActivity {
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_activity);
showClippingCoupon();
}
}
My dialog code
void showClippingCoupon()
{
LayoutInflater layoutInflater = getLayoutInflater();
View toastView = layoutInflater.inflate(R.layout.clipping_coupon_toast, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this).setView(toastView);
AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(true);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
TextView couponCodeText = (TextView) toastView.findViewById(R.id.coupon_code_text);
couponCodeText.setText("Y34UIDEFDK");
ImageView closeButtonImageView = (ImageView) toastView.findViewById(R.id.coupon_close);
if (closeButtonImageView != null)
{
closeButtonImageView.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
dialog.dismiss();
}
});
}
dialog.show();
}
My activity layout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/layout">
</FrameLayout>
I am trying to load a custom dialog view in my activity. This is how it is supposed to look like.
But this is what I get
This is what it looks in a preview.
Here is the layout of the dialog.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/coupon_text_color_v2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:id="@+id/coupon_clip_success_icon"
android:src="@drawable/ic_check_circle_green"
app:layout_constraintStart_toStartOf="parent"
android:contentDescription="@android:string/ok"
app:layout_constraintTop_toTopOf="parent"
android:layout_margin="16dp"
android:layout_toStartOf="@+id/coupon_body"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="wrap_content"
android:id="@+id/coupon_body"
android:focusable="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="@+id/coupon_clip_success_icon"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:id="@+id/coupon_copied_text"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="8dp"
android:layout_marginTop="16dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="48dp"
android:text="@string/coupon_code_copied"
android:textAppearance="@style/Small"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/coupon_code_text"
android:layout_below="@+id/coupon_copied_text"
android:layout_marginStart="16dp"
android:layout_marginBottom="16dp"
android:text="Test"
android:textAppearance="@style/Small.Bold"
/>
</RelativeLayout>
<ImageView
android:id="@+id/coupon_close"
android:src="@drawable/ic_clear"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_constraintStart_toEndOf="@+id/coupon_body"
android:layout_marginEnd="8dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_gravity="top|right"
android:contentDescription="@string/close" />
</androidx.constraintlayout.widget.ConstraintLayout>
What should I be doing to remove the white space at the dialog's right?