How to disable / enable dialog negative positive buttons?

前端 未结 7 1265
太阳男子
太阳男子 2020-11-28 23:30

Please look at the custom dialog below. I have an edittext field on the dialog and if the text field is empty I would like to disable the positiveButton. I can

7条回答
  •  旧巷少年郎
    2020-11-28 23:50

    You can write a listener to the edit text box, and try to enable or disable buttons. This is a sample code for xamarin.

    var dialog = builder.Create();
    
    dialog.Show();
    
    var btnOk = dialog.GetButton((int)DialogButtonType.Positive).Enabled = false;
    
    _enterTextDialogEditText.AfterTextChanged += (sender, e) => {
      if (!string.IsNullOrEmpty(_enterTextDialogEditText.Text)) {
        dialog.GetButton((int)DialogButtonType.Positive).Enabled = true;
      } else {
        dialog.GetButton((int)DialogButtonType.Positive).Enabled = false;
      }
    };
    

提交回复
热议问题