Hide keyboard automatically when navigating between fragments - android

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.

Related

Dismissing a DialogFragment when the soft keyboard is hidden

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?

Set android focus on touch?

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()

Custom Keyboard and default keyboard

Ok so I have a custom keyboard view that opens on touch event on a edit text but when i use it on a device the default keyboard shows and it overlaps my custom keyboard so i have to click back button for the default keyboard to go down and for my custom keyboard to actually show on screen. I have tried Inputmethodmanager method to hide default keyboard implicitly. It hides on the emulator when i enable physical keyboard input but not on a full touch device. Please help me out.

android make soft keyboard always visible

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.

Keyboard comes with tabbar.. how to get only keyboard

I have one problem in the Tabbar with text box, when i click on text box keyboard comes but the tabbar comes over the keyboard, and i want to get the keyboard only tabbar should not be comes over the keyboard.
Screen scroll automatically when keyboard comes.
Add this property in your Tab activity tag in AndroidMainfestfile,
android:windowSoftInputMode="adjustPan"

Categories

Resources