What is the purpose of the method showSoftInput in class InputMethodManager? I am new to android, and well for me the documentation is not very clear :
Explicitly request that the current input method's soft input area be shown to the user, if needed. Call this if the user interacts with your view in such a way that they have expressed they would like to start performing input into it.
From what I have understood it opens the keyboard, am I am right? Why should we use this method, doesn't touching an EditText open automatically the keyboard??
No, touching an edit text doesn't automatically open a soft keyboard. That's just the default behavior. Under the hood, when you touch the edit text a series of events occurs. Eventually the Android framework will call showSoftInput on the IMS of the keyboard. This is the keyboard's chance to decide it doesn't want to show for some reason and return false if it is not shown. For example, I believe at Swype we overrode this not to show the keyboard if there was a hardware keyboard on the device already slid out, on the theory they then wanted to use the hardware keyboard.
Most of the time you're just going to either use the default implementation here, or do a few minor checks then fall back to the default implementation.
Related
I have a very simple UI that has one entry control to enter phone number and a button. The entry control has a handler for removing border around it. When the entry control got focus, keyboard pops up. But when I try to tap outside the entry control such as on the screen empty area, the keyboard does not dismiss and the entry control does not lose focus. Also since the button is at the bottom of the screen, therefore, the soft keyboard hides it and there is no way to tap the button. The button can only be tapped if I press the Android device back button.
At present, I have not checked this behavior on an iOS device.
This was not a problem in Xamarin Forms though. I searched a lot on Internet and found that it is currently a bug in MAUI.
I tried to attach a tap gesture on the parent layout control and invoked platform-specific code to hide the keyboard but it seems the entry does not lose focus and in turn the tap gesture event is never called.
However, the entry control should lose focus automatically when I tap outside the entry control (such as on the screen) and the soft keyboard should automatically dismiss.
Please provide a workaround if there is any.
Known bug. Removing the focus sometimes helps. Sometimes you need to do Disable/Enable in sequence. (I go with the second).
If you want, you can read this for example:
https://github.com/dotnet/maui/issues/12002
(Most disturbing part, considering this is know bug for half year+)
We can leave the behavior how this is for now in NET7 and provide an
API in NET8 that lets users toggle this behavior on/off for iOS and
Android
I have a custom android keyboard. On long press popup keyboard is shown how it should. The problem is, when it pops up, the keyboard behind is darkenes.
How can i disable this, except overriding the default KeyboardView onDraw?
One more thing: how can I make the poped up keyboard buttons selected without pressing on them? In Google keyboard, when you press on a "." key, you just keep moving your finger and it selects the key on the popup. But on the default implementation of KeyboardView, you have to press on the key.
This has been bugging me for a month, hope you can help!
Solution: don't use KeyboardView. Its meant for quick prototyping, when you need a basic keyboard and are working on other things like autocorrect algorithms. No serious keyboard actually uses it, and it isn't required (you can return any view from onCreateInputView). As you ramp up UI complexity, it just quickly becomes unable to deal
I want to make an editable layout in android where the edit option and keyboard opens up only when the user does a double tap on the box, so that the screen remains readable and keyboard comes up only when needed.
to give you a basic idea:
1) Create your own GestureDetector as described in many answers, for example here
2) Set an OnTouchListener for your View and check for the onTouchEvent() method result. Return true from onTouch() to prevent the system from showing the keyboard on EditText single tap.
3) Use the InputMethodManager to show/hide the soft keyboard as needed.
I'm not quite sure why a normal single tap won't suffice, but you might want to check out this answer to a similar question.
I want to determine the duration of user taps or swipes on the keyboard so that I can determine how long words/letters take a person to input using the soft keyboard.
Is there a way to detect only that the user has touched the keyboard (I don't care about what they are entering at this point)? I am using a TextWatcher to get the end of the tap/swipe, but I have not had any success getting the beginning of the tap/switch when the user first touches the keyboard.
Is there a way to detect only that the user has touched the keyboard
Write your own input method editor (a.k.a., soft keyboard) that contains your desired time recording. Then, convince users to switch to use your input method editor.
I am using a TextWatcher to get the end of the tap/swipe
No, you are using a TextWatcher to detect changes to text in an EditText. Such changes may be from a user interacting with an input method editor. Or, they may be from the user using a physical keyboard. Or, they may be from action mode operations like cut and paste.
My Application needs to have two sources of input active at the same time: A bar-code scanner and the soft keyboard. When I pair a blue-tooth scanner, it is being treated as a physical keyboard. So, when this device is connected, the soft keyboard is not being displayed (soft keyboard is deactivated).
Is it possible to have both Physical Keyboard and Soft Keyboard active at the same time?
If not, what is the best approach towards solving the problem? Do I have to implement a custom View that sinks key press events? Is there any keyboard App on the Market that does this?
How do I, programatically, turn the Physical Keyboard On and Off? This is the toggle button 'Use Physical Keyboard' setting (I found the screenshot of this setting here:
It is not possible to have both Physical Keyboard and Soft keyboard active at the same time. It is enforced by InputMethodService function onEvaluateInputViewShown. you can check the documentation here.
/**
* Override this to control when the soft input area should be shown to
* the user. The default implementation only shows the input view when
* there is no hard keyboard or the keyboard is hidden. If you change what
* this returns, you will need to call {#link #updateInputViewShown()}
* yourself whenever the returned value may have changed to have it
* re-evaluated and applied.
*/
public boolean onEvaluateInputViewShown() {
So unless you are implementing your own IME wherein you can overide onEvaluateInputViewShown it is not possible to have both Physical and softkeyboard to be active at the same time.
Regarding your last question i am not sure but I think there is no way to programmatically hide the hardKeyboard. Though it doesn't have the solution you should check this question