关于自定义对话框

时间:2017-06-22 05:05:57

标签: java android

我正在尝试创建一个dialog框,标题,正文(消息),ok -option。

我怎样才能逐行分开它们(我的意思是按行分为三部分)?

这是我使用的代码:

public void dialog_vhe(View view){
    String button_details;
    button_details = ((Button) view).getText().toString();

    AlertDialog.Builder builder2 = new AlertDialog.Builder(this);


    builder2.setMessage("   You can use either your garnt number or TRN.\n" +
            "   The Visa Grant Number can be found on your visa grant notification.\n " +
            "   The Transaction Reference Number can be found in your ImmiAccount and on any correspondence from the department. ")

            .setCancelable(false)
            .setNegativeButton("Ok", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });

    AlertDialog alert2 = builder2.create();
    alert2.setTitle("REFERENCE NUMBER");
    alert2.show();
    setContentView(R.layout.activity_visa_holder_enquiry);
}

1 个答案:

答案 0 :(得分:0)

使用自定义对话框布局并使用此代码对其进行充气

 Dialog dialog = new Dialog(MainActivity.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.referral_code_dialog);
    dialog.setCancelable(false);
    close = (TextView) dialog.findViewById(R.id.close);
    apply = (TextView) dialog.findViewById(R.id.apply);
    error = (TextView) dialog.findViewById(R.id.error);
    referral = (EditText) dialog.findViewById(R.id.referral_code);
    dialog.show();

    close.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });

    apply.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });