WebView padding on top and bottom



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


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.


I will try to set it programmatically.

When I use xml attribute, it doesn’t work


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


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