JS to Android control WebView set padding

Source: Internet
Author: User

There is an interface in the project to display a Web page, very simple, put a webview on the OK, but the return button, the UI is designed to display a translucent bar at the bottom, there is a return button on the left. This bar appears above the content. I have a concern, is that if the bottom of the content needs to be manipulated, although see, but can not operate. At first it was natural to think of setting up a padding, but there was a bug in Android's WebView.

After thinking a lot of ways, by judging WebView slide to the end, and then do their own animation, but the effect is not too good

if (utils.dip2px (This, mwvcontent.getcontentheight ())-mwvcontent.getheight ()-Mwvcontent.getscaley () = = 0  ){}

The judging condition is a bit of a problem, sometimes he is, but not equal to 0, this can add a range. And then it was in the beginning I also found some judgments on the Internet, they are directly used Getcontentheight (), in practice I found in this return is DP, we need to turn into PX.

I also want to rewrite WebView, ability is not very good, can only think of re-measurement height, in the OnDraw () method to draw the bottom of the blank, but none can be achieved.

Not reach the effect, so I do not willingly continue to search the Internet under the WebView set Padding, found in a great God's: http://blog.csdn.net/janronehoo/article/details/45100551

I have thought through JS to change the Web page, but I js not too much, not ah! When I see the title, not happy, the most important thing is to solve the problem. Thank you, great God.

The Code of the Great God:

Webview.setwebviewclient (new  webviewclient () {    @Override    publicvoid onpagefinished (WebView view, String URL) {        webview.loadurl ("javascript:document.body.style.padding=\" 8%\ "; void 0 ");    });

And I think the effect of nearly point, I tried to change the change, tried Padding-bottom not, paddingbottom can, anyway do not understand, there is no scrutiny, implementation on the line, and then is how to set a fixed height, rather than a percentage.

Mwvcontent.loadurl ("javascript:document.body.style.paddingbottom=\" "+ Utils.px2dip (This, Mtvback.getheight ()) + "px\"; void 0 ");

It should be noted that the execution of JS needs to be at the end of page load, the onpagefinished () method in the Great God Code , and sometimes some pages are not called, so you need some other, such as Onreceivedsslerror () method, which is also seen in some great gods, thanks to the sharing of the great God.

JS to Android control WebView set padding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.