You can add SfDataForm to alert dialog using the AlertDialog builder in Xamarin.Android.
Initialize SfDataForm, set DataObject and other requirements of SfDataForm in the button click event handler.
private void OnLogin(object sender, System.EventArgs e)
{
var dataForm = new SfDataForm(this);
dataForm.DataObject = new LoginInfo();
dataForm.CommitMode = CommitMode.PropertyChanged;
dataForm.RegisterEditor("Password", "Password");
…
}
Initialize the AlertDialog.Builder and set SfDataForm as builder view.
private void OnLogin(object sender, System.EventArgs e)
{
…
var builder = new AlertDialog.Builder(this);
builder.SetCancelable(false);
builder.SetTitle("Enter credentials");
builder.SetPositiveButton("Ok", (s1, e1) => {
});
builder.SetView(dataForm);
…
}
For AlertDialog, set SoftInptMode to specify the action needs to be done on showing the soft keyboard. And, clear the NotFocusable flags to enable the soft keyboard and focus the fields of SfDataForm.
private void OnLogin(object sender, System.EventArgs e)
{
…
AlertDialog dialog = builder.Show();
dialog.Window.SetSoftInputMode(SoftInput.AdjustPan);
dialog.Window.ClearFlags(WindowManagerFlags.NotFocusable | WindowManagerFlags.AltFocusableIm);
}
Output