AlertDilog
弄一个button
<Button
android:id="@+id/button_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="616dp"
android:text="AD"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.518"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
找到它
Button button = findViewById(R.id.button_1);
设置一个点击事件
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
builder.setTitle("这里输入标题").setMessage("设置文本").setNegativeButton("按钮一", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//按钮一的点击事件
Toast.makeText(LoginActivity.this,"NegativeButton",Toast.LENGTH_SHORT).show();
}
}).setPositiveButton("按钮二", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//按钮二的点击事件
Toast.makeText(LoginActivity.this,"PositiveButton",Toast.LENGTH_SHORT).show();
}
}).create().show();
}
});
如果有红色的,就应该是LoginActivity,把它改成你的Activity的名字,比如MainActivity