I'm developing a PhoneGap-based application and I googled much about how to make my webview adjust its height when virtual keyboard appears, or at least get height of the virtual keyboard. I found a lot of posts (including stackoverflow) which says that
android:windowSoftInputMode="adjustResize"
must be set in the manifest and I did that. I also found that for PhoneGap config.xml there's
<preference name="android-windowSoftInputMode" value="adjustResize"/>
setting and I pasted that too. I also tried combined value 'stateVisible|adjustResize' (not just 'adjustResize') for both parameters, but it seems to me that they both have NO EFFECT. I don't know, maybe I'm doing something wrong, but you can check the screenshots from the emulator (Android 4.0.3, but I also tried 4.1.2 and 4.2.2):
http://screencast.com/t/Mm0mw8c693 - keyboard visible
http://screencast.com/t/lZ2DomqeRR - keyboard hidden
On the screenshot I intentionally captured my manifest and config.xml settings, so you may see they're actually there.
I even recorded short video - http://screencast.com/t/xI9PMcMJxxx
As you may see, no any viewport resizing occur when keyboard shown / hidden.
I also checked window.innerHeight using console.log() and it stays same for both visible and hidden keyboard.
Please, give me some advice.
windowSoftInputMode="adjustResize" does not work if your app is in fullscreen mode (setting fullscreen to true in config.xml). It is Android's issue not Cordova. the issue CB-4404 was filed in Cordova bug tracker for months but recently it turns out that it is working as intended on Android bug tracker.
I solved the problem by setting fullscreen to false since it wasn't a problem for my app not to go fullscreen.
I found I needed to to 3 things to resolve this issue, and prevent the actionBar from hiding itself, from scrolling out of view when the soft keyboard was brought up.
1) In AndroidManifest.xml, in the activity in question, I needed the line:
android:windowSoftInputMode="adjustResize"
The original problem is that adjustPan was present in the line above. At first, just the change above fixed the problem.
The project I am on uses fragments. In the onCreateView method, a different fragment had the line:
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
That line, unfortunately, overrode the adjustResize parameter in the Application manifest, and after that other fragment was displayed, the fragment that I fixed broke again. So, to fix the new break, I did 2 additional things.
2) I deleted the SOFT_INPUT_ADJUST_PAN line from the onCreateView method of that other fragment, because it did not need that line anyway.
3) In the onCreateView method of the fragment with which I am primarily concerned, I added the line:
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Actually, doing either of items 2 or 3 would solve the problem. I did both to be thorough.
either you can set this property in android.manifest explicitly to "adjustNothing" then you do not need to set "fullscreen" mode to false.
but you have to update it every time you update/add android platform.
Related
I have had feedback from Pixel 3/4 users that the bottom of the screen on this app is cut off, obscuring buttons and possibly other controls that the user requires.
This has only started happening on Android 10. The app contains both Xamarin.Android axml and Xamarin.Forms xaml layouts for the views (the particular page that you are viewing below is Xamarin.Forms).
I don't want to set margins, paddings, gravity or such like on the entire app as obviously that would impact non Android 10/Pixel users. I don't really want to check the operating system version and programatically change those properties as that seems quite hacky and will quickly become unmanageable.
I've looked for something similar to a UseSafeArea property for navigation bars rather than notches but there doesn't seem to be any. Is using WindowInsets the only way to this or has someone else had/solved this issue?
How it looks (controls at bottom are obscured):
How it should look (and does on every other device, the data is different here but it's the view that matters):
I had a similar issue which I solved by removing a few lines of code that were there to fix a bug that has since been fixed in Xamarin Forms.
It directly relates to this forum topic: https://forums.xamarin.com/discussion/87176/windowsoftinputmode-doesnt-work-in-xamarin-forms-android
If these lines exist in your MainActivity.cs, try removing them and see if that works:
Window.SetSoftInputMode(Android.Views.SoftInput.AdjustResize);
Window.SetSoftInputMode(SoftInput.StateHidden);
AndroidBug5497WorkaroundForXamarinAndroid.assistActivity(this);
I'm using android.support.constraint.ConstraintLayout to layout a simple card's content views.
I'm getting random changes in my XML, every time, when:
I switch to Android Studio's layout editor's Design tab
Or when I have a Preview pane turned on (in this case changes happens even more often during my changes).
Those random changes include:
Removal of my manually defined layout margins (eg. layout_marginEnd)
Changing values of my manually entered margin value
Adding tools:layout_editor_absoluteX values
Questions:
Anyone else experience this Android Studio's feature?
How to switch this "feature" off, so my layouts would not be destroyed?
Where to report this bug to Google or JetBrains?
Please take a look to this file diff, which was made automatically when switched to Design tab:
PS.: My Android Studio version is 2.2.3; I'm running it on macOS Sierra.
Update #1
As suggested, after making layout_height="match_parent", I get modifications less often, but still my XML gets messed-up, when I edit layout in Layout Design'er:
This time I wanted to set layout_marginTop through Design UI (selected line is what I wanted to add), but I also got those other unwanted changes:
layout_marginStart removed;
app:layout_constraintBottom_toBottomOf referenced IDs got a prefix of "+" sign, which means, those IDs are newly declared, so when I'll use Goto declaration functionality, I'll have to choose it from the list - not a desired behaviour.
tools:layout_editor_absoluteX gets added. I could ignore it, but still - not what I'd want to happen.
In my case removing the layout constraint and adding it again fixed the disappearing margins.
I'm on Android Studio 4.1.1.
I have been noticing the same issue with Android Studio 2.3, the code changed automatically every time I went from text view to design view on a recent project with ConstraintLayout. - I'm pretty sure it happens with RelativeLayout or whatever other layout you want to use as well.
I guess it is some type of auto code generation bug linked to the design view, I have not been able to find a way to turn it off yet.
I'm not sure this helps because I'm confident you've already realized it, but if you work almost completely in text view, the issue never happens.
I occasionally use design view to begin my layout but once I have something working, staying in text view personally seems to be faster for the development process.
As #JoeyJubb mentioned, using layout_height="match_parent" solves this problem. At least XML is not modified. Although, sometimes preview is generated incorrectly.
In my case upgrade to newest gradle dependecy helped:
com.android.support.constraint:constraint-layout:1.0.2
Also I started using 0dp instead of match_parent for layout_width
I do understand that similar issues have been reported here but mine is somewhat different.
I have recently upgraded the com.android.support:appcompat-v7 to v21 and com.android.support:support-v4 to v19.
Everything seemed normal on a pre-lollipop device but when I started to test the device on Android L, two issues appeared:
The softkeyboard was covering EditText
In the webview, system wasn't resizing, pushing the form-fields to the top as it normally should, rather did on pre-lollipop devices.
I read various articles and added the following line to my AndroidManifest.xml file:
android:windowSoftInputMode="adjustPan". It did push the edittextfields on top of the keyboard removing the toolbar from the view however it did not resize the view in webview and still covered the form fields at the bottom.
And after the changes, the app on pre-lollipop devices is malfunctioning in the same fashion as well.
Any help will be very much appreciated.
Extract from android-manifest:
<activity
.....
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan">
...
</activity>
I am using the Theme.AppCompat.Light.NoActionBar theme for my app.
Incase anyone lands here facing the same issue, the behavior occurs because "they" (Google) have changed the behavior of adjustPan moving forward from Android L.
To fix the issue, I am using a keyboard util in the library as indicated here.
A note from the developer is that this fix is to be used only in fragment/activity becaues this uses a GlobalLayoutListener which lowers the frameRate a bit but this is the only option to get it working
I've just started to rebuild my app for Android 5.0, using the appcompat support library. I've just finished implementing a transition featuring shared elements. It seems to work well, untill I add a webview.
I've made a video to demonstrate the glitch.
https://www.youtube.com/watch?v=MuuGZc0Vwow
As you can see, all's fine when I open the activity. When I close it, the glitch occurs. As you can see all elements fade out like they should, except for the webview. Which just hangs there until the animation is over, kinda ruining the entire smoothness of the animation.
How do I fix this? If it could be related to the way I've set things up I'd be happy to share some code.
Thanks in advance.
The reason why this glitch occurs is because WebView extends AbsoluteLayout. By default ViewGroups that are not "transition group"s and that have no background drawable will not be animated by the activity's window content transition. In order to fix the glitch with the WebView, you will need to call webView.setTransitionGroup(true) (or set the attribute in XML using android:transitionGroup="true"). This should cause the WebView to fade away as part of the activity transition instead of simply sitting there until being abruptly removed at the end of the transition.
As for the "Unable to create layer for WebView" error you are receiving, I imagine that is because the transition framework automatically creates a hardware layer for the WebView during the transition and for some reason the framework is crashing when it is trying to create the layer. This sounds like a totally separate issue related to Android's internal graphic pipeline though... I'm not sure I can give you a good answer about why the crash occurs without more information.
This issue is also discussed in the bottom of this blog post.
I have facing exactly this kind of random crash problem in webview in Marshmallow version. I have add attribute android:transitionGroup="true". but crash is happening, after that i have added android:hardwareAccelerated="false" in manifest where that activity is declared. After that random crash has solved in Marshmallow version and lower version too.
When I add a class to make appear a div (display:block) , suddenly view change to black screen. I touch the screen, elements in view still fire event.
How can I resolve the problem?
You should make sure you are using the most recent API (You can probably adjust this in eclipses android sdk manager).
If you still have any issues, make sure you have hardware acceleration on. You can adjust this in the manifest file:
<application
...
android:hardwareAccelerated="true"
...
>
If you still have an issue, try applying a css3 translate to something like your global body on app load. That will help to narrow down the issue. Otherwise, without some more code/information it's going to be hard to answer.
Let me know if I can help with anything else, but for what it's worth I haven't had this issue at all using the most recent android API and cordova 4.0.