diff options
author | Alan McGovern <alanmcgovern@users.noreply.github.com> | 2016-11-03 11:08:30 +0000 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-11-03 04:08:30 -0700 |
commit | a2fae62d8384f78c1b5f0ba3dc088000946479bc (patch) | |
tree | 45554567b06d192e98692a4294827c198f6f0126 /Xamarin.Forms.Platform.Android/KeyboardManager.cs | |
parent | 7afe69e932543e96fd9557f8a6d4bf75b36b4489 (diff) | |
download | xamarin-forms-a2fae62d8384f78c1b5f0ba3dc088000946479bc.tar.gz xamarin-forms-a2fae62d8384f78c1b5f0ba3dc088000946479bc.tar.bz2 xamarin-forms-a2fae62d8384f78c1b5f0ba3dc088000946479bc.zip |
Update ContextExtensions.cs (#502)
* [Android] Handle missing android services gracefully
When rendering inside layoutlib, like the Android Designer does,
we will not have access to the normal android services.
* [Android] Handle null InputManagers here too
Just in case this codepath is hit at some point during the
android designer's rendering codepath.
Diffstat (limited to 'Xamarin.Forms.Platform.Android/KeyboardManager.cs')
-rw-r--r-- | Xamarin.Forms.Platform.Android/KeyboardManager.cs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Xamarin.Forms.Platform.Android/KeyboardManager.cs b/Xamarin.Forms.Platform.Android/KeyboardManager.cs index eb89731b..e89ed9ef 100644 --- a/Xamarin.Forms.Platform.Android/KeyboardManager.cs +++ b/Xamarin.Forms.Platform.Android/KeyboardManager.cs @@ -23,7 +23,7 @@ namespace Xamarin.Forms.Platform.Android throw new ArgumentException("inputView should be of type EditText, SearchView, or TextView"); IBinder windowToken = inputView.WindowToken; - if (windowToken != null) + if (windowToken != null && inputMethodManager != null) inputMethodManager.HideSoftInputFromWindow(windowToken, HideSoftInputFlags.None); } } @@ -40,8 +40,10 @@ namespace Xamarin.Forms.Platform.Android { if (inputView is EditText || inputView is TextView || inputView is SearchView) { - inputMethodManager.ShowSoftInput(inputView, ShowFlags.Forced); - inputMethodManager.ToggleSoftInput(ShowFlags.Forced, HideSoftInputFlags.ImplicitOnly); + if (inputMethodManager != null) { + inputMethodManager.ShowSoftInput(inputView, ShowFlags.Forced); + inputMethodManager.ToggleSoftInput(ShowFlags.Forced, HideSoftInputFlags.ImplicitOnly); + } } else throw new ArgumentException("inputView should be of type EditText, SearchView, or TextView"); |