My activity has an EditText field and I want Soft Keyboard to be always visible in the activity. I set
android:windowSoftInputMode="stateVisible"
in the manifest, but it results in animated appearance of Soft Keyboard when the activity starts. I need SoftKeybard to appear in full size at exactly the same time when activity starts, without animation.
I don't think this is possible.
You can make the keyboard to automatically show when the activity or fragment is created but the keyboard will be dismissed when the user presses the backbutton.
Related
First of all this question is not about how to hide keyboard programmatically.
We all know that we can get keyboard to appear automatically for EditText by getting focus on start and android:windowSoftInputMode="stateVisible".
Question: I have an EditText in a Fragment being focused and keyboard is shown. I navigate to another Fragment and the keyboard remains shown. How can i get the keyboard to hide automatically when the EditText (that the keyboard is for) is no longer visible?
Yes i could have hide the keyboard programmatically but i can't shake off the feeling that there must be a way to dismiss the keyboard automatically when it can be shown automatically.
I have two EditText views and one ImageView. My goal is to hide the ImageView when i am showing the keyboard (When the user have clicked on one of the EditText fields)
Then show the imageView again when the user have unfocused the EditText field or the keyboard is not visible anymore.
I have tried tons of different ways to do this. But nothing really works as intended. Do you guys have any idea how i could achieve this
Have you tried to detect if the keyboard is opened ? How do I Detect if Software Keyboard is Visible on Android Device?
Make debug and when is opened try to hide image . imageview.setvisibility (GONE)
if it does not work you can try to change layout
Make 2 layouts and switch visibility if the keyboard is open /closed
You can add a OnFocusChangeListener to the EditText,when you click the EditText,it will get focus,and then you can hide the ImageView.
<activity android:name="SearchResultsActivity"
android:windowSoftInputMode="adjustPan"/>
adjustPan:
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.
regards! :)
You can do one thing, place UIView-> UIImageView -> UITextfield1-> UITextField2.Handle the UIImageView hiding state in textfield delegates which are Begin and End editing delegate methods
I have a simple DialogFragment that contains an EditText. When the DialogFragment is created the soft keyboard is shown immediately and the EditText gains immediate focus by using:
mEditText.requestFocus();
getDialog().getWindow().setSoftInputMode(
LayoutParams.SOFT_INPUT_STATE_VISIBLE);
In fact, what I have is essentially like the example given in this blog:
http://android-developers.blogspot.co.uk/2012/05/using-dialogfragments.html
When the back button is pressed, I wish for the DialogFragment to be dismissed. What actually happens is that the first back button press causes the soft keyboard to be hidden. A further back press is required to dismiss the DialogFragment.
I was quite surprised that there doesn't seem to be a simple API solution for this (such as setting a flag) as I'd have thought it'd be a common requirement.
Having searched on SO the best option seems to be to detect when the soft keyboard has been hidden, and then call dismiss() on that event. Such possible solutions for detecting the soft keyboard is hidden are:
EditText with soft keyboard and "Back" button
How to check visibility of software keyboard in Android?
Before I go ahead and use one of the above solutions, is there any other means I should consider dismiss of the entire DialogFragment and soft keyboard with one hit of the back button?
Why not using a cancel button instead of exploiting the back one?
I have this issue: in my app, when user taps on EditText bar, keyboard pops up. After that, it is impossible to get rid of keyboard. When back button is pressed, whole application just turn off.
How can I make sure, that when user taps on some other object (not EditText), keyboard will be removed? Or at least, how to make it possible to hide keyboard by tapping back button?
Thanks.
in xml for EditText this will make keyboard dismiss when press enter on keyboard
android:imeOptions="actionDone"
You can hide the keyboard simple by overriding onBackPressed in your Activity and using the following code:
InputMethodManager inputMethodManager = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(anyView.getWindowToken(), 0);
Note that anyView can be any view that is attached to your current window.
You can see it working in my app called Magic Annotator. See method hideSoftKeyboard()
I have an Activity which performs searching within my app. I have this Activity set as the handler for the hardware search button. This all works great.
If a user navigates to my Activity, enters a search query and then clicks on the "Search" button then I dismiss the soft keyboard via:
InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(etQuery.getWindowToken(), 0);
etQuery is my EditText field.
However, if a user taps the hardware search button, then the search input overlap is shown, and the user is allowed to enter text, which they do, upon clicking "Go" my Activity gets the input and performs the search successfully. However, the soft keyboard is still visible.
Even though I do call the above keyboard dismissal code, it doesnt actually work. I assume because the window [token] that initiated the soft keyboard is NOT in fact the etQuery EditText - it was initiated by the Hardware Search facility. Thus asking it to close based on the EditTexts token has no effect.
At this point, I don't really care who opened the soft keyboard, I just want it to close.
How can I force the soft keyboard to close regardless of who opened it?
I solved this by adding the following attribute to the activity in the manifest:
android:windowSoftInputMode="stateHidden"