How to work this HTML CSS Extension

How to use it.

Because i create a html css code via ChatGPT but i don't know hoe to use it, i also try but css not apply.

please guide me how to work it, if any use it pls provide right blocks and also if error in code please figure out it.

thanks in advance :sparkling_heart:.

    @SimpleFunction(description = "Registers a TextView component for HTML formatting.")
    public void Register(AndroidViewComponent component) {
        textView = (TextView) component.getView();
    }

    @SimpleFunction(description = "Sets the HTML-formatted text to the registered TextView.")
    public void SetHtmlText(String text) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            textView.setText(Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY));
        } else {
            textView.setText(Html.fromHtml(text));
        }
    }

    @SimpleProperty(category = PropertyCategory.APPEARANCE, description = "Gets the text of the registered TextView.")
    public String GetText() {
        return textView.getText().toString();
    }

    @SimpleFunction(description = "Sets CSS styles to the registered TextView.")
    public void SetCssStyles(String css) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            textView.setText(Html.fromHtml(
                    "<html><head><style>" + css + "</style></head><body>" + textView.getText() + "</body></html>",
                    Html.FROM_HTML_MODE_LEGACY));
        } else {
            textView.setText(Html.fromHtml(
                    "<html><head><style>" + css + "</style></head><body>" + textView.getText() + "</body></html>"));
        }
    }

image

If asking for help here, please use AppInventor as your development environment.

@TIMAI2 sorry, but blocks is same for also, pls help me

image

You probably want to set this all to a webview, not a textview, by creating suitable html/css.

Best I can say is that it appears you have done well to identify the shortcomings of using chatgpt to create an extension...I could be wrong, though.

1 Like

Undoubtedly Chat GPT is a good tool but it is useful only if you know what you are doing exactly.
Half baked knowledge is very dangerous.

1 Like