Я реализовал пользовательский AlertDialog для своего приложения, который работает должным образом со всеми протестированными устройствами, за исключением, в частности, устройств Samsung, работающих на Android 9 с использованием интерфейса Samsung One.Для упомянутых устройств Samsung, когда я создаю Диалог, он всегда отображается внизу экрана, а не в центре.
Мой пользовательский AlertDialog
public static class DialogViewHolder {
private CustomButton btnAccept, btnCancel;
private CustomTextView title, message;
private AlertDialog alertDialog;
private View view;
private Context context;
private LinearLayout bg;
public DialogViewHolder(Context context) {
this.inflateView(context); // Should be the first
this.buildAlertDialog(context);
this.context = context;
}
/**
* Inflates the custom view
*/
private void inflateView(Context context) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
this.view = inflater.inflate(R.layout.custom_alert_dialog, null);
}
/** Builds the alert Dialog */
private void buildAlertDialog(Context context) {
// Create Builder Configuration
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.CustomDialog);
builder.setCancelable(false);
builder.setView(this.view);
}
}
Я уже пытался поиграть с моими файлами макетов, чтобы убедиться, что это не случайность, но затем я подтвердил, что этопроисходит только на устройствах Samsung под управлением Android Pie.
Правильно ли было предположить, что это как-то связано с пользовательским интерфейсом Samsung One?Из того, что я видел с пользовательским интерфейсом, большинство диалогов, использующих указанный пользовательский интерфейс, отображают диалоговое окно с предупреждением в нижней части экрана.Моя конечная цель - сохранить свой собственный AlertDialog в центре экрана.
Макет пользовательского диалога AlertDialog
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
<LinearLayout
android:id="@+id/dialog_bg_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@color/alert_background_color"
android:orientation="vertical">
<RelativeLayout
android:layout_width="@dimen/logout_container_width"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingTop="@dimen/logout_padding_top"
android:paddingRight="@dimen/logout_padding_left_right"
android:paddingLeft="@dimen/logout_padding_left_right">
<com.example.dialog.custom_views.CustomTextView
android:id="@+id/alert_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/logout_padding_top"
android:gravity="center"
android:textAlignment="center"
android:textColor="@color/alert_title_color"
android:textSize="@dimen/logout_header_title_size"
app:font_trait="Bold" />
<com.example.dialog.custom_views.CustomTextView
android:id="@+id/alert_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/alert_header"
android:gravity="center"
android:paddingBottom="@dimen/data_usage_header_margin"
android:paddingTop="@dimen/data_usage_header_margin"
android:textAlignment="center"
android:textColor="@color/alert_negative_button_color"
android:textSize="@dimen/logout_message_size" />
<com.example.dialog.custom_views.CustomButton
android:id="@+id/positive_button"
android:layout_width="match_parent"
android:layout_height="@dimen/logout_button_height"
android:layout_below="@+id/alert_message"
android:layout_marginBottom="@dimen/dialog_buttons_margin"
android:background="@color/alert_positive_button_color"
android:textSize="@dimen/logout_buttons_text_size"
app:font_trait="Normal"/>
<com.example.dialog.custom_views.CustomButton
android:id="@+id/negative_button"
android:layout_width="match_parent"
android:layout_height="@dimen/logout_button_height"
android:layout_below="@+id/positive_button"
android:background="@color/alert_negative_button_color"
android:textSize="@dimen/logout_buttons_text_size"
android:layout_marginBottom="@dimen/dialog_cancel_margin_bottom"
app:font_trait="Normal">
</com.example.dialog.custom_views.CustomButton>
</RelativeLayout>
</LinearLayout>
</FrameLayout>