6

I have a WebView (within a Fragment within a ViewPager with SlidingTabLayout).

When using the WebView to type, I want the layout to resize to make sure the input is visible.

When I click a text input in the WebView, the softkeyboard appears and the layout resizes. I'm able to enter my text and submit using the softkeyboard's return button or cancel input using the back button. After this, the keyboard disappears and the layout resizes back. Correct AdjustResize behavior.

However, when dismissing the keyboard by clicking outside the Softkeyboard (e.g. when entering a query in Google and pressing the Search button in the WebView) the keyboards hides and it takes about 2-3 seconds for the layout to resize (leaving a blank space for 2-3 seconds at the bottom of my layout). After that, when selecting the textinput, the keyboard overlays the WebView (adjustPan).

How can I make sure that when dismissing the keyboard by pressing the WebView, adjustResize behavior is maintained.

I've tried re-setting AdjustResize (e.g. from onTouch) but this has no effect:

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

I've also tried the following solution but this gives no change.

In addition, I've think this is probably not a focus issue (since the keyboard does appear, and the webview does respond). And I do ask focus from my View:

    webView.setFocusable(true);
    webView.setFocusableInTouchMode(true);
Community
  • 1
  • 1
Mdlc
  • 7,128
  • 12
  • 55
  • 98
  • I would like to create a new project, copy and paste some code and see the problem you are facing on my device. Could you make an edit so that this is possible? – NecipAllef Sep 15 '15 at 07:36
  • @NecipAllef I've posted some files already. However, if you'd like I can send you my full project. Email (24HR)l: m95YZL4xu2Sc@meltmail.com – Mdlc Sep 15 '15 at 09:28
  • I've seen your WebView source code and it was around 1.2k lines of code and I believe most of them are not even related to your problem. If you can provide some code that enables us to observe the problem but also isn't hard to compile or debug, you can get help faster. So I suggest you create a sample project and share it. I believe it is possible via Github. – NecipAllef Sep 15 '15 at 09:53
  • @NecipAllef Yes, I'll work on that. But I still have to determine what's the cause of the issue, so it takes me a while to create this project. – Mdlc Sep 15 '15 at 12:16

1 Answers1

0

It turned out to be that when you perform layout translations on the WebView or if the WebView's layout is changed indirectly (e.g. when resizing an element above the WebView in a RelativeLayout that causes the WeView to also be resized) showing and hiding the keyboard can cause some strange behavior:

  • AdjustResize behavior can be lost (as indicated in the question)
  • WebView resize's after keyboard can take longer then normal.
  • WebView's performance decreases

What solved this issue for me, was to prevent layout changes in the WebView in any way (layout reload upon rotation does not appear to cause this). In my case I was showing and hiding the Toolbar causing the WebView to resize (and fill the screen).

Mdlc
  • 7,128
  • 12
  • 55
  • 98