android - 按需显示软键盘
您好,我将 edittext 控件包装到根据用户请求显示在屏幕上的控件上。它覆盖整个屏幕,直到用户按下键盘上的“完成”按钮。
我无法在屏幕上明确显示控件。仅当用户点击控件时才会显示。我错过了什么吗?
我什至尝试了这个,当我启动存在编辑文本的覆盖层时,它并没有出现:
customCOntrol.showKeyboard();
public void showKeyboard()
{
InputMethodManager imm = (InputMethodManager)_context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(this._textView.getWindowToken(), InputMethodManager.SHOW_IMPLICIT);
}
这是我在配置文件 android:windowSoftInputMode="stateHidden|adjustPan" 中屏幕本身上的设置
提前谢谢
Hi I wrapped edittext control onto a control that is being displayed on the screen at users request. It overlays the whole screen until user presses 'done' button on the keyboard.
I am not able to explicitly show the control on the screen. only when user taps into control only then its shown. Am I missing something?
I even try this and it does not brin it up when I launch the overlay that Edit Text exists on:
customCOntrol.showKeyboard();
public void showKeyboard()
{
InputMethodManager imm = (InputMethodManager)_context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(this._textView.getWindowToken(), InputMethodManager.SHOW_IMPLICIT);
}
here is the settig I have on the screen itself in the config file android:windowSoftInputMode="stateHidden|adjustPan"
Thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您正在调用的 showKeyboard 函数中:
这将从窗口中隐藏 softInput 键盘!
您想显示键盘吗?如果是,那么您会使用:
编辑:我认为您也可以从 InputMethodManager 切换键盘,尝试:
In your showKeyboard function you are calling:
This will hide the softInput keyboard from the window!
Do you want to show the keyboard? If yes then would you use:
EDIT: I think you can also toggle the keyboard from the InputMethodManager, try:
@dropsOfJupiter
您可以在启动包含 EditText 引用的 Activity 或 Fragment 时执行以下操作: editText.requestFocus() 。这会将焦点移至 EditText 并带出软键盘。
我希望这有帮助。
@dropsOfJupiter
You can do: editText.requestFocus() as you launch the Activity or Fragment containing your EditText reference. This will give the focus to the EditText and will bring uo the SoftKeyboard.
I hope this helps.
问题:
我遇到了键盘不显示的问题。我受此答案启发编写了以下解决方案,但不是他们的解决方案!效果很好。简而言之,造成这种混乱的原因是请求焦点和 IMM 提供的服务只能在已创建且活动的视图上运行。当您在创建阶段
onCreate(Bundle savingInstance).. 或 onCreateView(LayoutInflater inflater...
执行所有这些操作并且视图仍处于初始化状态时,您将不会获得活动视图来操作我见过许多使用延迟和检查来等待该视图激活然后显示键盘的解决方案,但这是我基于 android 框架工作设计的解决方案:解决方案:
在您的活动中或片段覆盖以下内容确保您的视图具有访问权限(在活动/片段的顶部定义它):
PROBLEM:
I faced with this keyboard not showing up problem. I wrote the following solution inspired by this answer but not their solution! It works fine. In short the reason for this mess is that the request focus and the IMM provided service can only run on a view that is created and active. When you do all these on the creation phase
onCreate(Bundle savedInstance).. or onCreateView(LayoutInflater inflater...
and the view is still in initializing state, you won't get an active view to act on! I have seen many solutions using delays and checks to wait for that view to get active then do the show keyboard but here is my solution based on the android frame work design:SOLUTION:
in your activity or fragment override the following make sure your view has the access (define it in the top of the activity/fragment):