WebView padding on top and bottom

from the CommonsWare Community archives

At March 25, 2019, 4:29pm, relaxedsoul asked:

Hello!

I need to programmatically set padding for the web content in my WebView.

The Problem:
I have the toolbar on the top of the screen and the webView below it.
I need to make toolbar to translate Up when the scroll is performed.
I made it work, but previously I had a margin_top for the webView’s container, and now I need to allow webView to go higher. But in the beginning, it should be placed below the toolbar.

So, the Question:
How to set the top padding for the web view programmatically?
The html content I receive from the server is very complex, I very strongly need to handle that padding without Javascript. But if you think JS is the only solution, please can you explain the idea?

Thank you


At March 25, 2019, 4:46pm, mmurphy replied:

If the padding is coming from android:paddingTop or setPadding(), call setPadding().

If the padding is coming from the HTML, you will need to use JS to manipulate the DOM, I guess. The details of what to adjust and how to adjust it would be something you should discuss with the maintainers of the HTML/CSS/JS that you are loading.


At March 25, 2019, 9:15pm, relaxedsoul replied:

I will try to set it programmatically.

When I use xml attribute, it doesn’t work


At March 25, 2019, 9:21pm, relaxedsoul replied:

Even programmatically it doesn’t work. SetPadding() is not a solution


At March 25, 2019, 11:12pm, mmurphy replied:

Then you will need to manipulate the HTML. Or, see if adjusting the margins will give you what you want.