[英]Java how to get input for EditText from toggleSoftInput
I created EditText by drawing it on canvas so I have problem on making the keyboard appear when clicked and to make the EditText receive input. 我是通过在画布上绘制EditText来创建的,因此在单击时使键盘出现以及使EditText接收输入时出现问题。 After some searching, I found out that I can use InputMethodManager to make the keyboard appear to give inputs for EditText.
经过一些搜索,我发现我可以使用InputMethodManager来使键盘看起来像是为EditText提供输入。
Unfortunately, EditText does not receive any character inputs from anything pressed on the soft keyboard. 不幸的是,EditText不会从软键盘上按下的任何内容接收任何字符输入。
And I need to use imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
而且我需要使用
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
because when I used imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
因为当我使用
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
the soft keyboard did not appear at all when EditText is pressed. 按下EditText时,软键盘根本没有出现。
Code: 码:
if((int)event.getX() > 50 && event.getX()<400 && event.getY() > 50 && event.getY() < 200){
editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
editText.requestFocus();
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
How to solve this? 如何解决呢? Any working solution is welcomed.
任何可行的解决方案都值得欢迎。 Thanks!
谢谢!
This should work fine. 这应该工作正常。
EditText edit = (EditText) view.findViewById(R.id.passwordtextvalue);
edit.setOnKeyListener(this);
InputMethodManager imgr = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imgr.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
edit.requestFocus();
I have this in my app, and its working fine for edit text when I have the soft keyboard 我的应用程序中有此功能,使用软键盘时,它可以很好地编辑文本
Try this 尝试这个
EditText yourEditText= (EditText) findViewById(R.id.yourEditText);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.