C# 当输入获得焦点时隐藏键盘 处境
我有一个Android应用程序,它使用外置键盘,当C# 当输入获得焦点时隐藏键盘 处境,c#,android,xamarin,keyboard,android-softkeyboard,C#,Android,Xamarin,Keyboard,Android Softkeyboard,我有一个Android应用程序,它使用外置键盘,当条目控件获得焦点时,我想隐藏软键盘 参考文献 以下声明如下: 注意:如果用户的设备附带了硬件键盘,则不会出现软输入法 然而,在一些Android设备中,当条目获得焦点时,会出现软输入 在这些情况下,我如何才能隐藏软输入 提前谢谢 您可以使用此代码隐藏软键盘 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 获取Ed
条目
控件获得焦点时,我想隐藏软键盘
参考文献
以下声明如下:
注意:如果用户的设备附带了硬件键盘,则不会出现软输入法
然而,在一些Android设备中,当条目
获得焦点时,会出现软输入
在这些情况下,我如何才能隐藏软输入
提前谢谢 您可以使用此代码隐藏软键盘
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
获取EditText的实例
EditText editText = (EditText) findViewById(R.id.edittext);
要防止默认软键盘出现在编辑文本中,请覆盖以下事件
//显示自定义键盘
edittext.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) showCustomKeyboard(v);
else hideCustomKeyboard();
}
});
edittext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showCustomKeyboard(v);
}
});
edittext.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
EditText edittext = (EditText) v;
int inType = edittext.getInputType(); // Backup the input type
edittext.setInputType(InputType.TYPE_NULL); // Disable standard keyboard
edittext.onTouchEvent(event); // Call native handler
edittext.setInputType(inType); // Restore input type
return true; // Consume touch event
}
});
}
public void hideCustomKeyboard() {
keyboardView.setVisibility(View.GONE);
keyboardView.setEnabled(false);
}
public void showCustomKeyboard( View v) {
keyboardView.setVisibility(View.VISIBLE);
keyboardView.setEnabled(true);
if( v!=null ){
((InputMethodManager)getSystemService(Activity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}
public boolean isCustomKeyboardVisible() {
return keyboardView.getVisibility() == View.VISIBLE;
}
@Override public void onBackPressed() {
if( isCustomKeyboardVisible() ) hideCustomKeyboard(); else this.finish();
}
免责声明:-我已经在我的应用程序中实现了自定义键盘,我编写了本教程-这对我很有用:
public static void DisableSoftKeyboard (EditText editText)
{
((InputMethodManager)GetSystemService(Context.InputMethodService)).HideSoftInputFromWindow(editText.WindowToken, 0);
if (Build.VERSION.SdkInt >= BuildVersionCodes.Honeycomb) {
editText.SetRawInputType (InputTypes.ClassText);
editText.SetTextIsSelectable (true);
} else {
editText.SetRawInputType (InputTypes.Null);
editText.Focusable = true;
}
}
实施:
editText.FocusChange+= (sender, e) => {
DisableSoftKeyboard(editText);
};