Does the host activity of the dialog got restarted when the system show / hide the Soft Keyboard because of the focus change in dialog?
My application is Fragment-Driven. I have a lot of fragments going around. One of my fragment trigger an action to open a dialog. Inside that dialog, there is input field and when I tap on that input field, all the states of the UI on the host fragment (actually all the fragments, so must be affecting on Main Activity) got reset. In my activity, I have already put this.
android:configChanges="keyboardHidden|orientation|screenSize"
So, by right, even though the soft keyboard is being shown on Activity, it should not got restarted.
I don't think I need put any code because it is purely on the logic of how Android controls on soft keyboard shows / hide.
Edit: My question is NOT how to hide soft keyboard. My question is how to handle the LifeCycle restart when the soft keyboard appears.
The actual problem is, in my underlying activity, I am having ListView. Because of that, when the soft-keyboard appear, the system check on the view from the host activity and try to PAN those ListView.
Because of that, the getView ( .. ) of the Adapter of the ListView got called and the UI states insides the items in ListView got refreshed.
The activity or fragment does not got restarted when the soft-keyboard appear if you put
android:configChanges="keyboardHidden|orientation|screenSize"
in your Activity or Application.
For the time being, I solved this by putting
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
in my host activity. It will not resize / pan the UI of the Activity when the Soft Keyboard appear. But, it is ok for me. All of my UI insides Activity or Fragments are not requesting any input from User. All the inputs are requesting with separate Dialog UI.
The above code does NOT affect the resize / pan on the Dialog. But, if you wants to make sure, put this in your Dialog subclass.
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
I am NOT sure this is desirable way or not. But, it suits my situation and because this is my question, I feel I have an obligation to answer it when I find a solution.
please use this method to hide your soft keyboard .call this method from onactivity result.
public static void hideSoftKeyboard(Activity context) {
InputMethodManager inputManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputManager != null)
inputManager.hideSoftInputFromWindow(context.getWindow().getDecorView().getApplicationWindowToken(), 0);
context.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
Related
In my android application, I have a dialog in one fragment and this dialog contains a edittext, I use showSoftInput to let soft keyboard showing. But when I tap outside the dialog(not tap the keyboard button or edittext), the dialog should dismiss and it does. The weird thing is when the phone in portrait view the softkeybaord will not dismiss following the dialog but in landscape view the softkeyboard dismiss.
Anyone meets this case? And I find this in the android developer website:Note: Once the input method is visible, you should not programmatically hide it. The system hides the input method when the user finishes the task in the text field or the user can hide it with a system control (such as with the Back button)
I got one more solution to hide keyboard
InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
Add this on tap outside
I have found my root reason, it is because the host activity set:
android:windowSoftInputMode="stateHidden|adjustResize".
After I remove this, my problem is solved.
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 know this should not be a big challenge but it really drives me insane.
I am developing a simple soft keyboard input method and basically I have added a button to my softkeyboard, by pressing which, a dialog should pop up to prompt user to do some choices.
By far everything is ok about creating and opening the dialog. Since normally a dialog is created and displayed from outside an activity, so a flick solution could be to create a transparent activity which embedded the dialog in it. By doing so, I could easily start a dialog when user click the button on my softkeyboard.
But one tricky problem is: every time user click the button and the dialog (actually a dialog in a transparent activity) displays, it will always make my softkeyboard hide. I just need to start the dialog without any changes to the status of my softkeyboard -- I want my softkeyboard keeps showing when the dialog starts.
Here is a snapshot of Google Keyboard, it has the similar button which display a dialog and the dialog did not hide the keyboard, this is exactly what I want. So please anyone suggest me how to achieve this. Thanks so much.
THey aren't launching an Activity. They're launching a dialog. Which is tricky from an input method because its a service (you have to specify the dialog's window token to make it show) but doable.
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've created a soft keyboard inside a v4 support Fragment but I think I'm going about it incorrectly. The keyboard shows up OK, but I can't hide it (the back button closes the programme). Otherwise it works fine. I would like the hardware Back button to be able to close just the keyboard.
myKeyboard = new Keyboard(getActivity(), R.xml.my_keyboard);
myKeyboardView = (MyKeyboardView) getActivity().findViewById(R.id.my_keyboard_view);
myKeyboardView.setKeyboard(myKeyboard);
// this is a custom class to receive soft keyboard events
// just passes on the events to the Activity as normal
keyboardView.setOnKeyboardActionListener(new MyKeyboardListener(getActivity()));
To get the keyboard to show up, I use an OnClickListener on the target EditText with an animation and setting the Visibility to VISIBLE.
Should I be using this approach? I looked for a way to get the keyboard on the backstack but it's not obvious.