I have added a custom layout with parent layout as Constraint layout. In android 9 it is not able to take the width and getting truncated as shown in the image attached.
I am using DialogFragment to create a dialog.
Dialog image, this long white vertical bar is how the dialog is looking in android 9. Please ignore other white colours around.
Attaching the codes for the same -
<androidx.constraintlayout.widget.ConstraintLayout
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="wrap_content"
android:padding="@dimen/button_margin_top">
<!-- Title -->
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/dialog_title"
style="@style/AppTheme.PageTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:gravity="left"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:textColor="@color/dark_grey"
android:textSize="@dimen/text_xxxl"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Remove this device from the list?"/>
<!-- Description -->
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_xm"
android:textAppearance="@style/AppTheme.Disclist.Body"
android:textColor="@color/dark_grey"
android:textSize="@dimen/text_xl"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/dialog_title"
tools:text="Pause connection or block access at certain times. Pause connection or block access at certain times. Pause connection or block access at certain times."
tools:visibility="visible"/>
<!-- Positive Button-->
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/positive_button"
style="@style/AppTheme.LargeButton.Primary"
android:layout_width="match_parent"
android:gravity="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/description"
tools:text="Yes, remove Device"/>
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/negative_button"
style="@style/AppTheme.LargeButton.Secondary"
android:layout_width="match_parent"
android:gravity="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/positive_button"
tools:text="Cancel"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Java Codes for the dialog -
public class NewConfirmationDialog extends DialogFragment implements View.OnClickListener {
private static final String DIALOG_TITLE = "title";
private static final String DIALOG_DESCRIPTION = "description";
private static final String POSITIVE_BUTTON_LABEL = "positive_button_label";
private static final String NEGATIVE_BUTTON_LABEL = "negative_button_label";
private static final String CANCELABLE = "cancelable";
private String titleString;
private String description;
private String postiveButtonLabel;
private String negativeButtonLabel;
private boolean cancelable = true;
private boolean isCancelled = false;
public static final int ACTION_CLOSE = 0;
public static final int ACTION_POSITIVE = 1;
public static NewConfirmationDialog getInstance(String title, String description,
String positiveButtonLabel, String negativeButtonLabel,
boolean cancelable) {
return newInstance(title, description, positiveButtonLabel, negativeButtonLabel, cancelable);
}
public static NewConfirmationDialog getInstance(String title, String positiveButtonLabel,
String negativeButtonLabel, boolean cancelable) {
return newInstance(title, null, positiveButtonLabel, negativeButtonLabel, cancelable);
}
public static NewConfirmationDialog getInstance(String title, String description, String positiveButtonLabel) {
return newInstance(title, description, positiveButtonLabel, null, false);
}
private static NewConfirmationDialog newInstance(String title, String description,
String positiveButtonLabel,
String negativeButtonLabel, boolean cancelable) {
NewConfirmationDialog popupWidget = new NewConfirmationDialog();
Bundle args = new Bundle();
args.putString(DIALOG_TITLE, title);
args.putBoolean(CANCELABLE, cancelable);
args.putString(DIALOG_DESCRIPTION, description);
args.putString(POSITIVE_BUTTON_LABEL, positiveButtonLabel);
args.putString(NEGATIVE_BUTTON_LABEL, negativeButtonLabel);
popupWidget.setArguments(args);
return popupWidget;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
Bundle args = getArguments();
if (args == null) {
throw new IllegalStateException("argument is empty");
}
titleString = args.getString(DIALOG_TITLE, null);
description = args.getString(DIALOG_DESCRIPTION, null);
postiveButtonLabel = args.getString(POSITIVE_BUTTON_LABEL, null);
negativeButtonLabel = args.getString(NEGATIVE_BUTTON_LABEL, null);
cancelable = args.getBoolean(CANCELABLE);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.layout_new_confirmation_dialog, container, false);
//title
if (titleString != null) {
((TextView) view.findViewById(R.id.dialog_title)).setText(titleString);
} else {
view.findViewById(R.id.dialog_title).setVisibility(View.GONE);
}
//Description
if (description != null) {
((TextView) view.findViewById(R.id.description)).setText(description);
} else {
view.findViewById(R.id.description).setVisibility(View.GONE);
}
Button buttonPositive = view.findViewById(R.id.positive_button);
if (postiveButtonLabel == null) {
buttonPositive.setVisibility(View.GONE);
} else {
buttonPositive.setVisibility(View.VISIBLE);
buttonPositive.setText(postiveButtonLabel);
buttonPositive.setOnClickListener(this);
}
Button buttonNegative = view.findViewById(R.id.negative_button);
if (negativeButtonLabel == null) {
buttonNegative.setVisibility(View.GONE);
} else {
buttonNegative.setVisibility(View.VISIBLE);
buttonNegative.setText(negativeButtonLabel);
buttonNegative.setOnClickListener(this);
}
return view;
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = new Dialog(getContext(), R.style.CustomDialog);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
return dialog;
}
@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
}
Style -
<style name="CustomDialog" parent="Base.Theme.AppCompat.Dialog">
<item name="android:windowIsFloating">true</item>
<item name="android:windowTitleStyle">@null</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:background">@drawable/round_corner_dialog_background</item>
</style>
Any suggestion why this is showing up in Android 9 only ?