Webview

bishmedia

Member
Licensed User
Longtime User
Ok simple question (i hope)

I have a webview added to my app with several buttons which makes the webview show different urls.

My question is, when this is run different websites are larger than the webview?
Is there an option where i can always make the url fit the webview width wise???
 

bishmedia

Member
Licensed User
Longtime User
The only issue with the zoom is that when the page opens its already too big, you can +zoom but the -zoom is blanked out until you press +zoom!!!

I'd like it to fit to the window as soon as loaded!!!
 
Upvote 0

bishmedia

Member
Licensed User
Longtime User
Thanks Erel, i will leave as is i think, i just thought it would look more professional if it opened and fitted the window.

Many Thanks
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Upvote 0

bishmedia

Member
Licensed User
Longtime User
How would i instigate one of the above methods, i simply have..

B4X:
Sub btnDown1_Click
   WebView1.LoadURL("http://www.4barsrest.com")
End Sub

Many thanks
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Try this example code:

B4X:
Sub Process_Globals
End Sub

Sub Globals
   Dim WebView1 As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   WebView1.Initialize("")
   Activity.AddView(WebView1, 0, 0, 100%x, 100%y)
   
   '   apply webview settings AFTER the WebView has been added to the layout
   Dim WebViewSettings1 As WebViewSettings
   
   '   possible values are "CLOSE", "FAR" & "MEDIUM"
   '   default is "MEDIUM"
   WebViewSettings1.setDefaultZoom(WebView1, "FAR")
   
   WebViewSettings1.setLoadWithOverviewMode(WebView1, True)
   
   WebViewSettings1.setUseWideViewPort(WebView1, True)
   

   WebView1.LoadUrl("http://www.b4x.com/forum/basic4android-updates-questions/26204-webview.html#post151659")

End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

That shows the syntax to use.
If you experiment with different values for those three methods you'll see various results - sometimes the settings have no effect though.
A lot seem to depend on the web page that you load and how it is written.
Some pages have fluid HTML layouts that adapt to different sizes, some pages have fixed size layouts that don't adapt to small screens very well.

So try the example code with various different web pages and various different values for the three methods and see what you get.
It might be worth testing on different devices/emulators with different versions of Android as the WebView can behave differently from version to version.

The official documentation for the WebView WebSettings page can be found here: WebSettings | Android Developers, you'll see most of the methods have rather vague names and little documentation.
So a search on Google will likely help you to establish what the various methods do.

Martin.
 

Attachments

  • WebViewSettingsExample.zip
    6 KB · Views: 270
Upvote 0

bishmedia

Member
Licensed User
Longtime User
I keep getting the following error??

B4X:
Parsing code.                           Error
Error parsing program.
Error description: Unknown type: webviewsettings
Are you missing a library reference?
Occurred on line: 38
    Dim WebViewSettings1 As WebViewSettings
 
Upvote 0
Top