I know this answer has been asked multiple times but there has not been a legit answer that solves this issue. To this day, I cannot believe Google has not added a listener for the SoftKeyBoard. I am curious to know if anyone has a solution to listening to the backPress while the keyboard is visible? I am asking this because within the Google play store when the search is visible and you press back, it hides the search and the keyboard at the same time. I have recreated the search but cannot find a legit answer to closing a custom searchview and the keyboard at the same time. I have tried a lot of answers but none of them are working.
I am calling "adjustPan" within the Manifest MainActivity to prevent custom views from being shifted. "adjustPan" prevents the root layout from making room for the softKeyboard, rather the softKeyboard is above the root layout. So this eliminates any measure solutions, which have been the main solution to most of the answers.
android:windowSoftInputMode="adjustPan"
Here is the custom SearchView
It is likely that Google is not listening for the onBackPressed event - but rather configuration changes that involve the keyboard. If you want to hide something when the keyboard changes to "hidden" then monitor the configuration with onConfigurationChanged and it will have the same effect.
See this post: How to capture the "virtual keyboard show/hide" event in Android?
Related
This question already has answers here:
How to stop EditText from gaining focus when an activity starts in Android?
(54 answers)
Closed 4 years ago.
I have been trying to hide the keyboard when user enters an activity,i checked and tried various ways and method but the one I lost see is hide keyboard on button click. I don't want the keyboard to hide on only button, I want it to be hidden when the activity starts. I also tried to put the code in an onCreate method but still the same.another on I saw on Android arsenal was to click on any part of the screen to hide the keyboard was nice but still I still prefer the keyboard hidden when the activity starts, please is there any way hiding the keyboard when the activity starts?
Your solution is here
There's yet another point of contention to be aware of. By default, Android will automatically assign initial focus to the first EditText or focusable control in your Activity. It naturally follows that the InputMethod (typically the soft keyboard) will respond to the focus event by showing itself. The windowSoftInputMode attribute in AndroidManifest.xml, when set to stateAlwaysHidden, instructs the keyboard to ignore this automatically-assigned initial focus.
<activity
android:name=".MyActivity"
android:windowSoftInputMode="stateAlwaysHidden"/>
Almost unbelievably, it appears to do nothing to prevent the keyboard from opening when you touch the control (unless focusable="false" and/or focusableInTouchMode="false" are assigned to the control). Apparently, the windowSoftInputMode setting applies only to automatic focus events, not to focus events triggered from touch events.
Therefore, stateAlwaysHidden is VERY poorly named indeed. It should perhaps be called ignoreInitialFocus instead.
Write this line on oncreate method
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
First, I am happy with my activity's android:windowSoftInputMode="adjustNothing" settings. I don't want the bottom of my screen to offer anything when the keyboard is up. Instead, I want to "pause" (or call the onPause() methods of) the fragments that are completely blocked by the soft keyboard, and then resume them back once it is out of their view.
At least I expected the fragments to do so on their own. But from the docs, it looks like their onPause() is generally linked to their parent activity's onPause().
From the other related questions' answers here and elsewhere, I understand there is no easy way to get the state of the soft keyboard yet. And, even doing so by hook or crook, I don't want to call the onPause() and onResume() manually on each suspected fragment.
So, my practical question is: is it possible to make any fragment self-aware when its view is blocked by the soft keyboard? If yes, how?
And yes, I want to understand if there are any good reasons why Android does not call onPause() on fragments whose views are completely blocked, unlike it does for an activity's onPause(). I understand it does not do it even for an activity in case of the soft keyboard. But getting completely blocked (intentionally or unintentionally) by anything, like the soft keyboard, should have some impact on an active view's life cycle, I feel.
I hope it is not gushingly marked duplicate, as I am not asking to know the state of the soft keyboard in an activity, at least directly :)
Because of keyboard is neither activity no home screen. The same effect appears when you rollout notification bar
I have seen a lot of posts to perform the contrary but here is what I want to achieve. After the user has performed a search through the SearchView, I would like it to stay open but without it being focused or the keyboard being visible.
If it is unclear, just have a look at how search behaves on the Play Store app.
I have tried to give focus to an other View on the screen, to call clearFocus() or setFocusable(false) on the SearchView but nothing works.
Any ideas ?
Thanks
OK. I finally nailed it.
Best way to do it is to override onStartActvityForResult and to manually close the keyboard. This way, you can handle yourself the search and nothing comes to disturb the SearchView which remains in the required state.
I am trying to solve the issue that in my Webview, when a user selects a textfield, the keyboard that appears covers the text field below.
Instead, I need a behavior where the text field is moved right above the keyboard, like what the flag SOFT_INPUT_ADJUST_PAN would do.
Based on testing, it seems like by default on a Webview, it is displaying the keyboard below the field.
But my WebView is in fullscreen. I am calling this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN) in my activity);
and this seems to make android stop doing the default 'pan and scan' behavior.
I've tried to call
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
and even
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
but that did not fix it.
I need to set the activity to fullscreen because I want to hide both the title bar and the status bar, so removing it is not an option unless there is another way to hide the status bar.
Any idea on how to solve this issue?
Laurent
You need to remove FLAG_FULLSCREEN flag. There is a bug somewhere in the OS machinery and with some digging around i have found the following:
without any extra scroll view around web view adjustPan never worked for me. Unfortunatelly the add scroll view also not always helps.
adjustScroll works for me when FLAG_FULLSCREEN is not present for the activity the webview is in.
So to sum it up the safest option to go with when it comes to WebView is adjustResize not full screen activity.
For me this worked:
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
I would like to remove the navigation buttons at the bottom of the soft keyboard ( the buttons with the arrow- they act like a tab key to move between fields). I have had no luck trying to find a way to do this. Does anyone have any suggestions
What you're describing is device-specific, as each device has its own default soft keyboard. Unfortunately, you'll need to make a custom keyboard.
Look at the Keyboard class.
I don't believe it's possible to remove the button from the keyboard, but you can at least specify which neighbor the field gives focus to. See Handling UI Events on the Android Dev Guide.
Perhaps it's possible to set nextFocusDown to nothing, so the keyboard doesn't let the user navigate in that fashion. If that doesn't work, you might consider setting the field that takes focus next to setFocusable(false).