-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hide Keyboard in Android Entry and Editor when back key is pressed (#…
- Loading branch information
1 parent
461c203
commit 3551378
Showing
7 changed files
with
78 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using Android.Views; | ||
|
||
namespace Microsoft.Maui.Platform | ||
{ | ||
public interface IMauiEditText | ||
{ | ||
bool OnKeyPreIme(Keycode keyCode, KeyEvent? e); | ||
|
||
event EventHandler OnKeyboardBackPressed; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using Android.Content; | ||
using Android.Views; | ||
using AndroidX.AppCompat.Widget; | ||
|
||
namespace Microsoft.Maui.Platform | ||
{ | ||
public class MauiEditText : AppCompatEditText, IMauiEditText | ||
{ | ||
event EventHandler? _onKeyboardBackPressed; | ||
event EventHandler? IMauiEditText.OnKeyboardBackPressed | ||
{ | ||
add => _onKeyboardBackPressed += value; | ||
remove => _onKeyboardBackPressed -= value; | ||
} | ||
|
||
public MauiEditText(Context context) : base(context) | ||
{ | ||
|
||
} | ||
|
||
public override bool OnKeyPreIme(Keycode keyCode, KeyEvent? e) | ||
{ | ||
if (keyCode != Keycode.Back || e?.Action != KeyEventActions.Down) | ||
{ | ||
return base.OnKeyPreIme(keyCode, e); | ||
} | ||
|
||
this.HideKeyboard(); | ||
|
||
_onKeyboardBackPressed?.Invoke(this, EventArgs.Empty); | ||
|
||
return true; | ||
} | ||
} | ||
} |