How to create a Custom Dialog box in android?

后端 未结 22 2771
囚心锁ツ
囚心锁ツ 2020-11-21 07:06

I want to create a custom dialog box like below

\"enter

I have tried the foll

22条回答
  •  余生分开走
    2020-11-21 07:34

    Simplest way to create custom dialog box:

    1. Initialize and show dialog:

       ViewDialog alertDialoge = new ViewDialog();
       alertDialoge.showDialog(getActivity(), "PUT DIALOG TITLE");
      
    2. Create method:

      public class ViewDialog {
      
        public void showDialog(Activity activity, String msg) {
      
          final Dialog dialog = new Dialog(activity);
          dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
          dialog.setCancelable(false);
          dialog.setContentView(R.layout.custom_dialoge_feedback);
      
          TextView text = (TextView) dialog.findViewById(R.id.text_dialog_feedback);
          text.setText(msg);
      
          Button okButton = (Button) dialog.findViewById(R.id.btn_dialog_feedback);
          Button cancleButton = (Button) dialog.findViewById(R.id.btn_dialog_cancle_feedback);
          final EditText edittext_tv = (EditText) dialog.findViewById(R.id.dialoge_alert_text_feedback);
      
          okButton.setOnClickListener(new View.OnClickListener() {
      
              @Override
              public void onClick(View v) {
                  //Perfome Action
              }
          });
          cancleButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  dialog.dismiss();
              }
          });
      
          dialog.show();
      
          }
      }
      
    3. Create layout XML which you want or need.

提交回复
热议问题