I have a dialog box in my Android app; it is the only EditText control on the dialog (the others are spinners and buttons), and so it gets focus when the dialog is shown. This prevents the on-screen keyboard from ever showing up, meaning you can't easily enter any text into the box unless you have a hardware keyboard.
I believe (but I couldn't swear to it) that this is because the control starts with focus, and the system check as to whether to show the keyboard or not happens in the onfocus event. Is there any way the programmatically show the on-screen keyboard?
In order to implement the ability to force the keyboard open when the user presses a button on the screen then the following should help.
InputMethodManager inputMethManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethManager.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
However an alternative to help regain focus of the dialog window can be found below. This code should open the software keyboard for you by resetting any flags initially set by AlertDialog. This code should be placed after the creation of the dialog window.
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Related
Is there anyway to dismiss the iPhone keyboard or disable it from popping up at all while Appium tests are being run?
driver.hideKeyboard() doesn't work, half the time a "DONE" or "RETURN" button isn't present and I can't just tap randomly on the screen because I can not guarantee that the code won't accidentally tap a link or active element.
I don't understand why it doesn't just function like on Android and just never display the keyboard when using driver.sendKeys().
I've noticed the same and did a workaround by doing it like an actual user and clicking on the hide keyboard button. You might want to add a check to only click if the element is visible to avoid trying to close the keyboard when it's not there.
driver.findElement(By.xpath("your_keyboard_close_button")).click();
I am developing an android app in Java that needs to be set up as a keyboard.
I want to have a button that when the user presses my app shows the following dialog box:
This is a quick settings dialog box to allow the user to choose the input method (keyboard) it wants to use from now on. It is a default Android setting that is accessible to any user.
Normally this setting shows up when you press the following shortcut next to the android navigation bar when a keyboard is opened:
But in the context I am working on, this option is not visible to the user. So I want my app to be able to show this setting to the user when it presses a button.
I know an app that does this exact thing, so I know that it is possible. However, I don't know how to code a button that displays a system dialog box like this one.
Could you please help me?
Thanks in advance!
After some more research I found the answer using an InputMethodManager object and the showInputMethodPicker() method in Java:
InputMethodManager inputMethodManager = (InputMethodManager) getApplicationContext().getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.showInputMethodPicker();
When the keyboard in my application is open, the BottomNavigationView is attached to the keyboard. So I added in AndroidManifest android: windowSoftInputMode = "adjustPan" but now the keyboard covers the bottom of the content. That is, ScrollView cannot change the maximum height to the keyboard. As if the fragment does not see when the keyboard is turned on. How can I show the keyboard so that the fragment adapts and the BottomNavigationView disappears. Help me pls.
Nothing can change the maximum height of the keyboard. The keyboard itself gets to decide that. There are only 2 actions you can take when the keyboard appears- pan or resize. The first will scroll your app so that the cursor appears on screen. The second will relayout your app in the space above the keyboard. Which if your screen is designed to can shrink extra space to make more stuff fit.
There is no option to hide certain views when the keyboard appears. There are hacks you can find that try to detect when the keyboard appears, but they all have flaws and ways they break. Android isn't set up to enable you to know when the keyboard is onscreen. You can try one of those, but more realistically you're going to live with this behavior.
By default, Android dismisses the on-screen keyboard when a user presses Send on the keyboard or clicks on a Button on the UI. However, I am building a messaging app, and would like to keep the soft keyboard on the screen even if a user clicks Send or any other button on the UI. This is the standard behavior for messaging apps (Facebook's messages functionality, for example, or Google Hangouts), so I know it can be done.
I have tried the suggestions here (returning true from the onEditorAction method of OnEditorActionListener) and here (InputMethodManager.SHOW_FORCED). The first seems to work on API 2.3, but was unsuccessful on 4.2. The latter didn't work at all.
Any suggestions would be appreciated.
I have an app with ListView in it and I added search functionality to it. When I press on EditText and it opens keyboard, it pushes everything in the layout along with it.
Normal layout:
With keyboard:
As you can see; the ad, play button, seekbar are all pushed up along with the keyboard, but I don't want that. Is there a way I can avoid this?
I tried adding this to Manifest file:
android:windowSoftInputMode="stateUnchanged"
But that doesn't work.
You probably want to use "adjustPan".
From the documentation:
The activity's main window is not resized to make room for the soft
keyboard. Rather, the contents of the window are automatically panned
so that the current focus is never obscured by the keyboard and users
can always see what they are typing. This is generally less desirable
than resizing, because the user may need to close the soft keyboard to
get at and interact with obscured parts of the window.