I am launching the soft keyboard like this:
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInputFromWindow(buttonLayout.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
buttonLayout
is a simple button on my UI.
How do I extract what the user wrote (without using a EditText
field or maybe hiding the EditText
) so the user can't see or click on it?
Without an EditText you're going to have a hard time.
An InputMethod needs to be connected to a view. Whatever view you use, you need to override onCreateInputConnection
to return a custom InputConnection
object that at a minimum implements commitText (for word input), deleteSurroundingText
(for deletes), and sendKeyEvent
(for keyboards that assume you're in dumb mode), and all of the completion functions. Input connections are complicated things and you'll screw up 3rd party keyboards like Swiftkey and Swype if you don't get it right. I really don't suggest doing this.
If you want to do this your best chance of getting it right is to claim your window is a TYPE_NULL
input type. Most keyboards will dumb themselves down and assume you only accept the simplest commands in that mode. But you can't count on it.
I'd look at the InputConnection
returned by the EditText
class and copy as much of it as possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With