iOS Question Set backgroundcolor of webview

schimanski

Well-Known Member
Licensed User
Longtime User
With the following code, I load an image to a webview to zoom it in and out. Is it possible to set the backgroundcolor of the webview? The area under the image is always white:

B4X:
Sub Process_Globals
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private wv As WebView
End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.Title = "Page 1"
    wv.Initialize("iv")
    Page1.RootPanel.AddView(wv, 0, 0,100%x, 100%y)
    wv.Color=Colors.red
   
    wv.ScaleToFit=True
    wv.SizeToFit
    NavControl.ShowPage(Page1)
       
    Dim ImagePath As String = (File.DirAssets & "/minion.png")
           
    Dim w As String = "100%"    'Bildbreite wird auf die maximale Breite des Webviews gesetzt'
    Dim h As String = "auto"    'Bildhöhe wird automatisch angepasst'
           
    Dim TempHtml As String = "<html><body><img src=" & ImagePath & " width=" & w & " height=" & h & "></body></html>"
    wv.LoadHtml(TempHtml)
End Sub

screen1.png
 

Attachments

  • webview.zip
    16.4 KB · Views: 240

JanPRO

Well-Known Member
Licensed User
Longtime User
Hi,
you can use css (style attribute):

B4X:
Dim Color As String = "red"
    Dim TempHtml As String = $"<html style="background-color:${Color}"><body><img src=${ImagePath} width=${w} height=${h}></body></html>"$

By the way, using a smart literal string, makes reading the code much easier.

Jan
 
Upvote 0
Top