Xamarin Android EditText enter key
The best approach would be to use the EditorAction
event that is designed to be triggered on the Enter key press. It would be a code like this:
edittext_vonalkod.EditorAction += (sender, e) => { if (e.ActionId == ImeAction.Done) { btnLogin.PerformClick(); } else { e.Handled = false; }};
And to be able to change the text of the Enter button use imeOptions
on your XML:
<EditText p1:layout_width="wrap_content" p1:layout_height="wrap_content" p1:layout_below="@+id/editText_dolgozo_neve" p1:id="@+id/editText_vonalkod" p1:layout_alignLeft="@+id/editText_dolgozo_neve" p1:hint="Vonalkód" p1:text="1032080293" p1:layout_toLeftOf="@+id/editText_allapot" p1:imeOptions="actionSend" />
You need to mark the event as not being handled when the pressed key is ENTER. Place the following code inside your KeyPress handler.
if (e.Event.Action == KeyEventActions.Down && e.KeyCode == Keycode.Enter) { // Code executed when the enter key is pressed down} else { e.Handled = false;}