2

I use a generic webview to load html files in order to show help dialogs in my android app.

this.helpView = new WebView(this);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
            this.helpView.getSettings().setSafeBrowsingEnabled(false);
        this.helpView.getSettings().setJavaScriptEnabled(true);

The usage is pretty simple, when i want to show any help dialog a load any of the html files, included into the assets folder, into the helpView

 if (this.helpView.getParent() != null)
            ((ViewGroup) this.helpView.getParent()).removeView(this.helpView);

        this.helpView.loadUrl(url);

where url is something like: file:///android_asset/add_giveaway_help.htm? + Locale.getDefault().getLanguage()

Here is the trick: I've only one html file for each help situation but each file includes the help text in several languages each html file has a javascript function which reads the own url and check for the query parameter indicator of language.
according to this information some specific css class is injected into the html and only the desired language is shown

the javascript function is:

if(window.location.href.endsWith('pt'))
style.innerHTML = '.en { display: none; }';
else
style.innerHTML = '.pt { display: none; }';

however this is not working on android 16

both help texts are being shown... while other javascripts in the same html are working even on android 16

1 Answer 1

1
htmlData = "<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />" + htmlData;

// lets assume we have /assets/style.css file

webView.loadDataWithBaseURL("file:///android_asset/", htmlData, "text/html", "UTF-8", null);
Sign up to request clarification or add additional context in comments.

2 Comments

what is html data? the whole html page?
@RafaelLima yes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.