Android Question WebView Zoom still functioning via buttons after ZoomEnabled=False

JohnK

Active Member
Licensed User
I am using a WebView in my app. I turn off (ie set) ZoomEnabled = False. This works partially in that the user can not pinch-to-zoom. However, when they try, the two on screen buttons to zoom become visible, and at least one is enabled, so the user can click on the buttons to zoom the page in or out.

I am guessing its a bug with androids built in WebView, but does anyone know a way to disable this behavior when it is used within B4A?
 

JohnK

Active Member
Licensed User
It is a bug in B4A. Call WebView1.ZoomEnabled = False in your code. It will work.

Will be fixed in the next update.
Im confused, as I stated I was already calling "WebView1.ZoomEnabled = False" in my code already, and hence I posted it as a question. When you say "it will work" I am assuming you mean in the next version of B4A?

Until the next release, is there some specific Java I can call to fix it?
 
Last edited:
Upvote 0

JohnK

Active Member
Licensed User
Don't worry about getting the code, got off my own butt and found it:)
B4X:
WebSettings webSettings = wv.getSettings();
webSettings.setBuiltInZoomControls(false);
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Core.Jar does the same ((WebView)getObject()).getSettings().setBuiltInZoomControls(v);
Honestly can't find a problem inside my app.
I wrote an activity, when it was B4A 7.8 and don't see zoom buttons.
Do you ? I reduce real activity to minimum.
 

Attachments

  • test2.zip
    8.7 KB · Views: 83
Upvote 0

JohnK

Active Member
Licensed User
I wrote an activity, when it was B4A 7.8 and don't see zoom buttons.
Do you ? I reduce real activity to minimum.
I didn't see them either, until I actually tried to zoom the web page (with a failing pinch), and then they appeared. So, the actual pinch to zoom did not work (as expected with ZoomEnabled = False), however, by trying to zoom with a pinch, the zoom buttons became visible and also managed to zoom the page. Adding the Java code above appears to have changed this behavior.
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
When I set ZoomEnabled = True, I get zoom buttons without efforts. When False - nothing (on my API 27 smartphone).

Added ...
When I tried to output Log (webviewInstance.ZoomEnabled) the smartphone informs "Cannot get methods of class: com.android.webview.chromium.ContentSettingsAdapter, disabling cache." More detail search shows that a reason is "getSettings". Interesting, how to fix this problem.
 
Last edited:
Upvote 0

JohnK

Active Member
Licensed User
When I set ZoomEnabled = True, I get zoom buttons without efforts. When False - nothing (on my phone). Under which release of Android do you test ? I try under 8.1 on real smartphone (no idea how to make a pinch in emulator)

Added ...
When I tried to output Log (webviewInstance.ZoomEnabled) the smartphone informs "Cannot get methods of class: com.android.webview.chromium.ContentSettingsAdapter, disabling cache."
More detail search shows that a reason is "getSettings". If we can't get settings, probably we can't set something. Interesting, how to fix this problem.
It gets flakier...

I am running Havoc-OS Oreo (8.1) which I compiled myself from source. So its a VERY customized ROM based off of LineageOS; with additional CPU Govs and IO schedulers I've added.

Now, the thing that gets very weird is that I reuse the same webview for displaying some pages without zoom, and some with. So I am switching .ZoomEnabled between true and fails, and calling the above Java with true or false as needed. When I first load a page, I set zoom disabled (ie = false) and call the above java code with false also. And, everything works perfectly. Then I display another page and turn zoom on (and the above java code with true), and that all works great. However, when I load the next page and turn zoom off (ie .ZoomEnabled=false and the Java with false) I get the strange half way situation where pinch does not work, but the zoom buttons will appear AND work, if I try to pinch the page.
 
Upvote 0

Erel

Administrator
Staff member
Licensed User
Im confused, as I stated I was already calling "WebView1.ZoomEnabled = False" in my code already, and hence I posted it as a question. When you say "it will work" I am assuming you mean in the next version of B4A?

Until the next release, is there some specific Java I can call to fix it?
Which version of B4A are you currently using?
 
Upvote 0

JohnK

Active Member
Licensed User
WebView.ZoomEnabled should work properly. The problem I posted about is related to the zoom enabled property in the designer.
Ok then, i'd like to point out the behavior I have seen as above.

So:
1. Load a page, set ZoomEnabled = false. All works as expected. Actually maybe the java code above is hiding the buttons in this case....I think originally the buttons would appear without the Java code, if the user tried and failed a pinch to zoom. So I think its really this case, for the default behavior under B4A. Running Oreo.
2. Then load another page, set ZoomEnabled = true. Pinch to zoom works, and the buttons appear and also work. As expected.
3. Load another page, set ZoomEnabled = false. Pinch to zoom does not work, however, attempting a pinch makes the zoom buttons visible, and incorrectly operable.

It really looked like a internal issue with the webview, and hence I did not think it was a B4A issue. And even more so now, as my above Java code appears to have fixed step 1, but fails for step 3, so it makes me even more suspicious its a webview issue. But I could definitely be doing something wrong.

And to re-state the case, I am not in the designer, but running an app.
 
Upvote 0

JohnK

Active Member
Licensed User
It is best if you upload a small program that demonstrates it.
So here is a quick demo.Simply start a new project, add this code to the activity.
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim htmlResults As WebView
    Dim b1 As Button
    Dim b2 As Button
    Dim b3 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Dim ItemHeight As Int = 64dip
 
    b1.Initialize("b1")
    b2.Initialize("b2")
    b3.Initialize("b3")
 
    b1.Text = "1"
    b2.Text = "2"
    b3.Text = "3"
 
    Dim W As Int = Activity.Width
 
    Activity.AddView(b1, 0, 0, W/3, ItemHeight)
    Activity.AddView(b2, W/3, 0, W/3, ItemHeight)
    Activity.AddView(b3, W/3 * 2, 0, W/3, ItemHeight)
     
    htmlResults.Initialize("htmlResults")
    Activity.AddView(htmlResults, 0, ItemHeight, Activity.Width, Activity.Height - ItemHeight)
End Sub

Sub b1_Click
    htmlResults.LoadUrl("https://www.google.com/")
    htmlResults.ZoomEnabled = False
End Sub
Sub b2_Click
    htmlResults.LoadUrl("https://www.google.com/")
    htmlResults.ZoomEnabled = True
End Sub
Sub b3_Click
    htmlResults.LoadUrl("https://www.google.com/")
    htmlResults.ZoomEnabled = False
End Sub

When you click "1", it all works as expected. ie NOT zoom-able, and if you try, no zoom buttons appear.
When you click "2", again it a all works as coded, in that zoom is enabled and the zoom buttons appear when you pinch
However, when I click "3" (or 1, its the same code), pinch to zoom is disabled as coded, BUT by attempting a pinch (or even a finger scroll) the zoom buttons become visible and they actually do the zoom.
Screenshot_B4A_Example_20181024-184447.png

I have not checked if its some kinda timing thing with zoomable set before the page finishes loading etc etc It appears to me to be some kinda web view bug, but I could be wrong.

============edit===============
removed the dud "add a reference to HTMLTextView library"
 
Last edited:
Upvote 0
Top