2015-11-28 3 views
0

Я хочу, чтобы виртуальная клавиатура исчезла после нажатия на поиск. Это код, который я до сих пор:Скрыть клавиатуру после поиска в Xamarin

query.EditorAction += (sender, e) => { 

      if (e.ActionId == ImeAction.Search) 
      { 
       HideKeyboard(); 
       pushSearch(); 
      } 
      else 
      { 
       e.Handled = false; 
      } 
     }; 

private void HideKeyboard() { 
     InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService); 
     imm.HideSoftInputFromWindow(query.WindowToken, 0); 
    } 

В XML:

<EditText 
     android:id="@+id/query" 
     android:layout_width="fill_parent" 
     android:singleLine="true" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:imeOptions="actionSearch" 
     android:inputType="text" 
     android:hint="Zoek totem" /> 

This это при вводе (перед нажатием лупы) и this после.

Если я отлаживаю и устанавливаю точку останова на pushSearch() внутри if, она никогда не вызывается.

Кто-нибудь знает, что я забыл?

ответ

0

Попробуйте это:

private void HideKeyboard() 
    { 
     View View = CurrentFocus; 
     if (View != null) { 
      InputMethodManager inputManager = (InputMethodManager)GetSystemService (Context.InputMethodService); 
      inputManager.HideSoftInputFromWindow (View.WindowToken, HideSoftInputFlags.None); 
     } 
    } 
+0

Нет, то же самое. Он выходит из фокуса, но клавиатура остается. [Это] (http://i.imgur.com/8jS27MO.jpg) при наборе (перед нажатием увеличительного стекла) и [это] (http://i.imgur.com/g4RnLjt.jpg) после. –

+0

Откуда вы вызываете метод? Активность или фрагмент? –

+0

Это активность –

0

Попробуйте, возьмите маркер окна из currentfocus:

InputMethodManager inputManager = (InputMethodManager)this.GetSystemService (Context.InputMethodService); 
      inputManager.HideSoftInputFromWindow (this.CurrentFocus.WindowToken, HideSoftInputFlags.NotAlways); 
+0

Нет, все тот же. –

Смежные вопросы