I have a pretty simple screen with a couple of EditText widgets and a button. In the emulator, when I click on the EditText widget, a virtual keyboard comes up. However, I can't seem to get rid of it. Clicking on an empty space on the screen does not make it go away. Only clicking the virtual Return key or the hardware Back button makes it disappear.
I don't have a real Android phone handy, so is this an emulator only thing or will it be like this on the actual device. If it is, what can I do to make the virtual keyboard go away, when I click elsewhere on the form?
Click the back button. They keyboard is an activity. There's not an easy way to remove the keyboard when clicking on a random area of the screen.
AngryHacker , I woud refer you to this post how to close/hide the android soft keyboard.
Hope this helps.
I think in the emulator you can press Escape to hide the keyboard. On a real device there is a hide button on the keyboard or you can press elsewhere in the ui. That's how it works on my HTC Desire S anyway.
I lived this problem and i resolved it. This problem is about InputMethodManager.SHOW_FORCED value in my project. When i open keypad using SHOW_FORCEDthen when i try to close keypad, keypad was not closing.
For Example :
activity.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(view, InputMethodManager.SHOW_FORCED);
If you use above way to open keypad, you may try to change SHOW_FORCED value with SHOW_IMPLICIT value
For Example :
activity.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
I have the Galaxy S2 which is running Andriod 2.3.6.
I was having issues with the keyboard not moving out of the way after entering the needed text when logging into websites. I found that hitting the hardware return button does take the virtual keyboard out of the way. But occassionally it will take the web browser back one page. Which is frustrating because then I have to re-enter the log in info for whatever web site I'm connecting too. Hopefully Android 4.x has solved some of these glitchy issues.
You can achieve this by doing the following steps:
Make the parent view(content view of your activity) clickable and focusable by adding the following attributes
android:clickable="true"
android:focusableInTouchMode="true"
Implement a hideKeyboard() method
public void hideKeyboard(View view) {
InputMethodManager inputMethodManager =(InputMethodManager)getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
}
Lastly, set the onFocusChangeListener of your edittext.
edittext.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
hideKeyboard(v);
}
}
});
Source
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();
I'm developing a scientific app in Android Studio. It works smoothy.
The set of source code files is not small, but, as I don't have practically user interface, there is only one activity and there is no intent.
All initialization code is inside OnCreate. Most of times, my app preserves all data, when he gets out of the foreground.
However, maybe (I cannot find a pattern of this event) he loses all data and restart (shows a white screen for 2 / 3 seconds), even if the cell phone don't enter in lock screen and there are just 2 apps running.
There are situations that I comute for another app (like WhatsApp) and resumes for my app, and my data was gone. The app restart again.
There is no error message, no logcat. Nothing.
Mostly, when I lock the screen and enter again, all my app data is there.
PS: My orientation is locked.
PS 2: I've read all related question and there is no hint for me. Based in one answer, I've tried to put in onCreate the following code.
if (!isTaskRoot() {
&& getIntent().hasCategory(Intent.CATEGORY_LAUNCHER)
&& getIntent().getAction() != null
&& getIntent().getAction().equals(Intent.ACTION_MAIN)) {
finish();
return;
}
No changes for me.
Update:
I've stumbled in solution. it can be read in my own answer. it's related to undesired back button effect for one-activity-app (read here and here ).
For me, as my application has only one activity, back needs to be like a home button: exit the app but preserve all activity data. My app has a real exit button, where the user shows that really wants to do this.
It's my first app that I developing in mobile world and, for extension, Android world
Some problems seems to me like that it is only possible find the solution if one has a hint about its solution. it's a contradiction. One doesn't know but has to know to solve that don't know!
And, in this situation, it's not the case. No hints. Just question marks.
Before, I had not noticed any pattern. People sometimes act so automatically ... However, suddenly the penny dropped.
I've stumbled in solution. Fortunately!
Not in a million years could I suppose that if someone has an activity and presses Back button, (right button in the bottom), you practically quit the application, even if it remains as a running app for the left button in the bottom (app switcher button)
When I've noticed it, I start to research with another focus. And I've discovered two sources: Disable back button in android and Android - Simulate Home click
So the solution is simply to make the Back button act like the Home button (middle button in the bottom). Return to the home screen without losing application data.
And this is done simply by putting in the onCreate, for my only activity, the following code.
override fun onBackPressed() {
val i = Intent(Intent.ACTION_MAIN)
i.addCategory(Intent.CATEGORY_HOME)
startActivity(i)
}
How to show a ProgressDialog from a background service that is unclosable in any way, displayed above whole screen, above any app, including keys? I mean a dialog exactly like the "Power off.. shutting down" one that is displayed when phone is shutting down, when you can neither do anything to make it disappear nor click anything below it.
PS. If the app needs to be a system app to create such dialog, that's not a problem for me.
Use this
ProgressDialog.setCancelable(false);
Create a full screen activity Using full screen Activity prevent back navigation by overriding onBackPressed()
Disable back button in android
I need to detect when the android software keyboard is hidden. My activity currently responds to when the hardware keyboard is hidden but the software keyboard looks like it can only be implied through a size changed event.
Does anyone know of a way that a view or activity can receive a notification when the software keyboard is hidden by the user cancelling out of keyboard mode?
Would forcing the sof tkeyboard to always be visible help?
You can add this to your Activity's xml file to ensure the softkeyboard is always visible in that Activity:
android:windowSoftInputMode="stateAlwaysVisible"
http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft
Theres no real way to check, but you can check if an action on it works or not
boolean isClosing = false;
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
isClosing = imm.hideSoftInputFromWindow(tabHost.getApplicationWindowToken(), 0);
This will return false if the keyboard was closed and true if it was open and is now being closed.
I solved this by just searching for the back key. When the back key is received I know that the soft keyboard will be cancelled.