简体   繁体   English

Android软键盘显示问题

[英]Android soft keyboard showing problem

I'm trying to control soft keyboard using this: 我正在尝试使用以下方法控制软键盘:

((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
            .hideSoftInputFromInputMethod(filterText.getWindowToken(), 0);
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
            .showSoftInput(filterText, InputMethodManager.SHOW_IMPLICIT);

But nothing happens on the device when i call this code. 但是,当我调用此代码时,设备上没有任何反应。 What can cause such behavior? 什么会导致这种行为?

If you have a 如果你有一个

EditText mEditText;

then you should set: 那么您应该设置:

InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mEditText, InputMethodManager.SHOW_FORCED);

For a textview, 对于textview,

TextView mtextview;

you can set: 您可以设置:

android:focusableInTouchMode="true"

android:inputType="text"

in the xml file. 在xml文件中。 Upon clicking on the textview, you will pop up the keyboard. 单击文本视图后,将弹出键盘。

I was having an issue where the soft keyboard was showing up when I first entered the activity and I didn't want it to. 我遇到一个问题,当我第一次参加活动时,软键盘出现了,我不想这么做。 This was messing up my scrollview. 这搞砸了我的滚动视图。 I was able to keep if from doing this by setting the following in the manifest file in the activity that I was dealing with: android:windowSoftInputMode="stateHidden" 我可以通过在正在处理的活动的清单文件中设置以下内容来避免这样做:android:windowSoftInputMode =“ stateHidden”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM