The original problem I am fighting is more complex but for investigating purposes I have simplified the test case to the following:
Single fullscreen activity
Programmatically created web view that occupies roughly half of the horizontal screen space, 90% of the vertical space and is added to the root view via within the onCreate call:
ViewGroup parent = (ViewGroup) getWindow().getDecorView().getRootView();
parent.addView(myWebView);
web view opens to google.com via:
loadUrl("http://google.com")
AndroidManifest.xml has the property:
"android:windowSoftInputMode="adjustPan"
When clicking on the search box on the google page the keyboard pops up but the web view itself is not shifted up as adjustPan indicates should happen. The main activity also has a native text field that when clicked will shift the entire layout (including web view) up as expected.
The behavior is present on 4.2.2 on both a Nexus 7 and Galaxy Nexus.
So the question is how can I have the windowSoftInputMode property adjustPan be applied correctly to a web view instance so that when the soft keyboard is displayed the entire web view is shifted up by the vertical space taken up by the keyboard.
Before I go down the road of trying to manipulate the layout manually within onMeasure I want to see if there is a consistent / better way to handle this. The browser obviously handles this situation correctly so not sure why the web view is not able to handle this.
One thing to note is that making the web view fullscreen or a separate activity are not possible options due to an existing architecture that I am not able to change.
If we use the full screen without action bar adjustResize will not work. See this thread for details adjustPan not preventing keyboard from covering EditText
Related
From what I could understand of the difference between AdjustResize and Adjust pan, it's that AdjustResize will change the height of all the components so that they can fit and squeeze into a "half screen" while AdjustPan will, only in the case where a view below the keyboard takes the focus, bring up this particular view so that it is accessible despite the keyboard.
However, in my case, I have a comment section which is a React Navigation view. In this view, I have a TextInput below it that must go up when the keyboard opens to write a comment. But when this TextInput goes up, it takes everything with it, including the elements of the previous view in the stack.
Picture from comment section (The gray above the keyboard is the textinput)
Picture from previous view in the stack if I go back (Only until the keyboard didblur event is sent and then everything returns to normal)
Why does the adjustPan seem to behave a bit like AdjustResize?
I've already tried to set AdjustNothing, but unfortunately it can't work because I don't receive keyboard events anymore.
I finally figured out where the problem was coming from.
I use
<SafeAreaInsetContext>
from the react-native-safe-area-context library because I need to do special management of the insets bottom for devices like iPhoneX or iPhone 11.
And in fact, when the Android keyboard opens, the insetBottom is redefined to take the keyboard size as well. So I had a padding on the bottom of my screen that was the size of my keyboard as soon as it opened. So the behavior is normal, and after correction, my AdjustPan behaves exactly as it should !
I am developing an application for android devices, which manages TV channels and shows. In it there is an option for the user to add channels in the system using a custom widget. The widget uses autocompleteTextView. My layout does not adjust itself when the soft keyboard appears.
These are the 2 states of the layout:
The keyboard blocks the user from viewing the options in the dropdown and the field below it. I have already tried the solution here and here. But none of them got it to work.
I want to move the layout of the widget itself, rather then the whole layout behind. How to go about this problem?
I am developing a softkeyboard I have tried several codes in the main.xml file but none of the codes display the keyboard in graphical view
Please Help
The soft keyboard won't show up in the graphical view because it is a custom view -- the graphical view is designed for basic android widgets only. When you start using anything but the main Android widgets (i.e. TextView, ScrollView, Button, etc.), you're going to have to code it in XML.
The keyboard's layout and drawing methods change dynamically based on the number of keys, the keyboard theme, key icons, etc. This happens at runtime and thus cannot be displayed before the app is run.
In my Android application running in a XOOM device, when I click in an Edittext the keyboard opens and hides the Actionbar. I don't want this to happen, how can I solve this? This is done by the Google Contacts app for the tablet for example.
EDIT:
I have several edittexts in which the user needs fo fill. At first, when the user clicked on one edittext on the bottom, the keyboard showed up and hide the edittext in which the user was typing, so he couldn't see what he was typing. I found it really bad, and to solve it I just added to the manifest: android:windowSoftInputMode="stateVisible|adjustPan"
But after that, now the screen adjust itselfs and hides the action bar.
The Google Contacts app does the same, but it magically doesn't hide the Action bar. How do they do it?
Use adjustResize instead of adjustPan. The framework will always try to keep the focused element on-screen by scrolling any parent views if necessary.
If your EditText field is not nested in some sort of scrolling container such as a ScrollView then your layout may be too tall to completely display when the keyboard resizes your activity. Try wrapping your form's layout in a ScrollView. This will also allow your app's content to scroll if it is running on a smaller screen device where it may have similar issues.
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.