android:windowSoftInputMode is set normally set on an Activity but I set everything up as one Activity that switches to different Fragments to support tabbing and I need different soft input mode for fragments.
My actual problem is that adjustPan causes text views within webviews to get covered by the keyboard and adjustResize was resizing a view that I was using for calculations and I thought setting different soft input mode for each fragment would be a good workaround.
try this each onCreateView of your fragment
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
i hope its works for you and reply
Related
I have a fragment that has some EditTexts that need to be filled by the user. There's a problem that the soft keyboard hides the EditText so that the user cannot see what they're writing. I don't want the user to scroll manually, I want the fragment to adjust so that it fits the keyboard automatically.
IMPORTANT NOTE: I have seen lots of suggestions to add android:windowSoftInputMode="adjustResize"
or android:windowSoftInputMode="adjustPan"in manifest. However, I want this action to be only for a specific fragment and not for all fragments within the activity.
I have tried adding requireActivity().window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
In onCreateView or in onCreate but nothing seems to change.
In my case,
android:windowSoftInputMode="adjustPan" and ScrollView
it's work for Fragment in Activity.
After looking up various questions on stack overflow, I have found that many other people had the following problems:
Background gets resized when soft keyboard opens
Soft keyboard opens when activity starts
The solution to both of these lies in the ActivityManifest.xml.
To prevent the background image from being resized when the soft keyboard opens, you can add android:windowSoftInputMode="stateVisible|adjustPan" to the <activity> in the manifest.
To prevent the soft keyboard opening when the activity starts, you can add android:windowSoftInputMode="stateHidden" to the <activity> in the manifest.
The fact that one solution requires stateHidden and the other requires stateVisible means that I cannot use both solutions. I am looking to prevent the soft keyboard from stealing focus on activity start but also prevent the soft keyboard from resizing the background when the user does decide to focus on the EditText.
Is there a viable solution to both of these issues?
The fact that one solution requires stateHidden and the other requires
stateVisible means that I cannot use both solutions.
Yes. But, you can use stateHidden|adjustPan.
Keyboard will not pop up unless user clicks on an EditText. And potential changes to your background will be in terms of positioning; scaling of the background will not occur.
If your EditText is wrapped within a parent container, set android:focusableInTouchMode="true" for that container. Basically, make that container receive the initial focus when the activity starts. Take a look at this link
Is any part of your layout a scrollable container (like ListView)? If so, try setting android:isScrollContainer="false" on that item in your XML layout.
If you have any views which have android:isScrollContainer="true", the layout manager will attempt to resize your layout when the keyboard pops up, regardless of `android:windowSoftInputMode'.
Here's a similar question: What does android:isScrollContainer do?
There are basically two ways to fulfill your requirement.
Just use the below activity tag
android:windowSoftInputMode="adjustPan|stateAlwaysHidden"
Or
Using
android:windowSoftInputMode="stateVisible|adjustPan" to the activity tag in the manifest.
Now with your EditText use following android:focusableInTouchMode="true" with android:focusable="false".
I have a TabActivity which has the tabs across the bottom of the screen. My first tab hosts an activity which consists of a fixed header layout at the top of the screen, and a ScrollView beneath it which contains several EditText controls. The ScrollView scrolls it's content fine between the header bar and the bottom tabs, the problem occurs when an EditText is tapped and the soft keyboard appears. I understand to control the behaviour of the views when the keyboard appears I need to use the windowSoftInputMode attribute in the manifest XML file. However I've tried both the following settings :
adjustResize - Gives the correct functionality for the ScrollView and the header layout remains fixed at the top of the screen. However the tab bar controls are pushed up on top of the keyboard.
adjustPan - The tab bar controls remain at the bottom of the screen beneath the keyboard (which is what I want) but the other views are pushed up by the keyboard meaning the header layout gets pushed up off the screen.
It seems I need characteristics of both settings, but they can't be used together. I've heard of the setting adjustNothing but if I try this my project fails to build as it doesn't recognise this setting. I guess I need my tab host activity to have adjustPan but my content activity to have adjustResize but it seems you can't combine the two as it's the tab host activity that takes precedence.
Any help greatly appreciated.
In the absence of any direct solution for this, I have resorted to a kind of hack. I have set my TabHost activity to adjustResize and then written code to hide/unhide the tab bar controls (TabWidget) when the soft keyboard appears/disappears. I managed to get a pretty good result in the end, using the technique here : Adjust layout when soft keyboard is on to detect the keyboard appearing/disappearing.
I have an activity with four tabs and every tab is implemented as a fragment. In one of these tabs I would like to prevent the soft keyboard from pushing up the view, while the keyboard should still push the views up in the other fragments. Does anybody know how to achieve this?
I cannot use the activity's windowSoftInputMode flag, because that would prevent it for the whole activity with all four fragments.
Try to change flag dynamically
Use the following to change the softInputMode for an Activity in your tab click listener.
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
In my android application, I have an EditText. When I click in this field, the soft keyboard appears, expanding from the bottom of the screen. It seems to actually modify my layout, pushing contents upwards. When I dismiss the keypad, it retracts, and I see my layout re-expand to take up the space it previously occupied.
Is there a way to get the keyboard to simply appear "on top" of my layout, so that I don't get this somewhat unpleasant relayout animation? The EditText is pinned to the very top of the screen, so I don't have to worry about the keypad hiding it.
Thanks
By default, Android should be using "Pan and Scan", which would work more or less how you described. The keyboard is displayed over your view, and you can scroll your view in the background. If you override the windowInputMode for you Activity, or Android determines that your Activity is resizable (because of the presence of a resizable field... ListView, ScrollViews, etc), it may resize your view instead, and it sounds like that's what you're running into. To force it to Pan and Scan try adding:
android:windowSoftInputMode="adjustPan"
as an attribute to the Activity element in your xml layout.
There's a third option as well. You can specify that when an EditText is selected it will be edited in full screen mode. The other controls in your view will be hidden, the user will be presented with just the keyboard, an EditText control, and optionally some other limited controls. If your EditText doesn't require a lot of context from other elements of your view, it may prevent a cleaner user interface. For more details, see: http://android-developers.blogspot.com/2009/04/updating-applications-for-on-screen.html
Add:
android:windowSoftInputMode="adjustResize"
to your activity attr in manifest.xml. Hope it will help.
This questions seems to state a resize is not desirable. I had the same issue, but adding
android:windowSoftInputMode="adjustNothing"
to the manifest file instead solved my problem.