How to customize web view content?

how to change font color, background color and font size in web viewer?

I don’t think so it’s possible …

Possible with this block.

component_method

1 Like

Cool … I forget about this block …

It is impossible to change the font color of the WebView text, since the WebView displays the font color from the given HTML. However, you can try this small extension for your other requests.

WebViewerAddon.aix (5.8 KB)

image

Source code (for anyone to modify):

package com.gordonlu.webvieweraddon;

import android.app.Activity;
import android.content.Context;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.AndroidViewComponent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;

@DesignerComponent(
        version = 1,
        description = "A non-visible extension that sets the background color and the font size of a WebViewer.",
        category = ComponentCategory.EXTENSION,
        nonVisible = true,
        iconName = "images/webviewer.png")

@SimpleObject(external = true)
//Libraries
@UsesLibraries(libraries = "")
//Permissions
@UsesPermissions(permissionNames = "")

public class WebViewerAddon extends AndroidNonvisibleComponent {

    //Activity and Context
    private Context context;
    private Activity activity;

    public WebViewerAddon(ComponentContainer container){
        super(container.$form());
        this.activity = container.$context();
        this.context = container.$context();
    }


    @SimpleFunction(description = "Sets the text zoom of the page in percent. The default is 100.")
    public void SetTextZoom(AndroidViewComponent webViewer, int textZoom){
        WebView wv = (WebView) webViewer.getView();
        wv.getSettings().setTextZoom(textZoom);
    }

    @SimpleFunction(description = "Gets the text zoom of the page in percent. The default is 100.")
    public int GetTextZoom(AndroidViewComponent webViewer){
        WebView wv = (WebView) webViewer.getView();
        return wv.getSettings().getTextZoom();
    }

    @SimpleFunction(description = "Sets the background color for this WebViewer.")
    public void SetBackgroundColor(AndroidViewComponent webViewer, int color){
        WebView wv = (WebView) webViewer.getView();
        wv.setBackgroundColor(color);
    }
}
2 Likes