【发布时间】:2019-07-09 10:27:39
【问题描述】:
我创建了一个自定义警报对话框以显示在我的应用程序中。它有一个 imageView、两个 textView 和一个按钮。我正在尝试在我的主要活动启动后显示此自定义警报对话框。我正在根据我的要求以单独的方法调用此自定义警报 dialog.show()。自定义警报对话框正在显示,但单击按钮即可没有被解雇,自定义警报对话框也显示额外的白色背景。
showCustomAlertDialog() 方法
public void showCustomAlertDialog() {
LayoutInflater layoutInflater = LayoutInflater.from(this);
final View promptView =layoutInflater.inflate(R.layout.reminder_alert_dialog, null);
final AlertDialog builder = new AlertDialog.Builder(this).create();
Button recordButton = (Button)promptView.findViewById(R.id.record_button);
recordButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
System.out.println("Dismiss the dialog");
builder.dismiss();
}
});
builder.setView(promptView);
builder.show();
}
reminder_alert_dialog 布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image_view"
android:layout_width="wrap_content"
android:layout_height="500dp"
android:background="@drawable/ic_alert" />
<TextView
android:id="@+id/greetings_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GOOD MORNING, KEVIN"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold"
android:layout_marginTop="200dp"
android:layout_centerHorizontal="true"/>
<TextView
android:id="@+id/medicines_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Have you taken your medicines today?"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="normal"
android:layout_below="@id/greetings_text"
android:layout_marginTop="50dp"
android:layout_centerHorizontal="true"/>
<Button
android:id="@+id/record_button"
android:layout_width="160dp"
android:layout_height="40dp"
android:background="#3BC4B8"
android:text="Record"
android:textSize="20sp"
android:textColor="#ffffff"
android:layout_below="@id/medicines_text"
android:layout_marginTop="60dp"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
【问题讨论】:
标签: android android-layout android-alertdialog android-dialogfragment