答案 0 :(得分:0)
要实现您所描述的内容,您需要在android中使用Dialog
。
final Dialog dialog = new Dialog(context_of_ur_class);
//if not title required
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
//add your layout in this
dialog.setContentView(R.layout.your_layout);
dialog.setCanceledOnTouchOutside(true);
dialog.show();
//example for button 1
Button one = (Button) dialog.findViewById(R.id.one);
one.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//do what ever
}
});
答案 1 :(得分:0)
首先声明全局private AlertDialog mAlertDialog;
private void buttonsDialog() {
AlertDialog.Builder mAlertBuilder = new AlertDialog.Builder(getActivity());
mAlertBuilder.setCancelable(true);//you can change this
mAlertDialog = mAlertBuilder.create();
LayoutInflater inflater = getActivity().getLayoutInflater();
View dialogLayout = inflater.inflate(R.layout.inform_dialog, null);
mAlertDialog.setView(dialogLayout);
Button button1 = (Button) dialogLayout.findViewById(R.id.alert_positive);
Button button2 = (Button) dialogLayout.findViewById(R.id.alert_negative);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//do your stuff
}
})
mAlertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
}
在buttonsDialog()
中致电onCreate
。并mAlertDialog.show
显示对话框。