0

我一直在开发 Xamarin Android 应用程序,我的活动包含多个编辑文本。当我通过单击它来聚焦编辑文本时,会出现软输入面板,但我希望它始终保持隐藏状态。我已经尝试过使用底层代码,但这不起作用,我也尝试使用 CurrentFocus 而不是 edittext。

InputMethodManager keyboard = (InputMethodManager)GetSystemService(Context.InputMethodService);
keyboard.HideSoftInputFromWindow(txtWerf.WindowToken, HideSoftInputFlags.None);

此外,我尝试在布局的 xml 和清单文件中使用 windowsoftinputmode。

编辑

 <application android:label="WMS" android:icon="@drawable/Icon">
 <activity android:name="Materiaal" android:windowSoftInputMode="stateAlwaysHidden"></activity>
 </application>

有没有人有想法?

4

3 回答 3

0

试试下面对我有用的代码。

您可以强制 Android 使用 InputMethodManager 隐藏虚拟键盘,调用 hideSoftInputFromWindow,传入包含焦点视图的窗口令牌。

 // Check if no view has focus:
 View view = this.getCurrentFocus();
 if (view != null) {  
 InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
  }

这将强制键盘在所有情况下都隐藏您甚至可以在您的活动下的清单中尝试 this。

 android:windowSoftInputMode="stateAlwaysHidden"
于 2016-01-07T11:51:30.063 回答
0

在每个 Edittext 控件上,您可以将 .ShowSoftInputOnFocus 设置为 false,并且在单击 edittext 时不会弹出键盘。

于 2016-01-13T10:01:14.133 回答
0

或者您可以只使用带有WindowSoftInputMode属性的活动属性:

[Activity(WindowSoftInputMode = SoftInput.StateAlwaysHidden)]
于 2017-08-31T08:05:33.443 回答