1

I have html5 with JS. It looks pretty good but is too big for (Nexus 5) screen and WebView becomes scrollable. I am looking long time for solution to make this view adaptive.

WebView mWebView;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gamelayout);

        mWebView = (WebView) findViewById(R.id.webView);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
        mWebView.setBackgroundColor(Color.parseColor("#001A0F"));
        mWebView.zoomOut();
        mWebView.loadUrl("file:///android_asset/anim1/Untitled-1.html");

    }
Sruit A.Suk
  • 7,073
  • 7
  • 61
  • 71

1 Answers1

1

Like the comments mention, you need to change the html.

Use the answer from this question to read the colors you want. For me, i needed to read colorSurface, i.e.:

        int bgColorResId = R.attr.colorSurface;
        TypedValue typedValue = new TypedValue();
        getContext().getTheme().resolveAttribute(bgColorResId, typedValue, true);
        int bgColor = typedValue.data

Then I needed to convert that int to a hexa string.

String colorStr = String.format("#%06X", 0xFFFFFF & bgColor)

Finally, you need to add this to your html string, e.g.

"<body bgcolor=\"" + colorStr + "\">"

You can do that for text color as well. Put the text color here

<style type="text/css">
body { color: #TEXTCOLOR };
</style>
cliveleehere
  • 316
  • 1
  • 6