What's the better solution to navigate to a certain point of a html page in a webview using android native buttons?
Is it possible to navigate html anchors?
What about using anchors like this:
First section
And then in your button's OnClick handler make your webview navigate to: http://yoururl.com/page.html#first
Does that work?
It seems there are some issues when the WebView is inside a ScrollView, you can read about it here: Android Webview Anchor Link (Jump link) not working
Related
I would like to know if there is a way to the WebView component to support a generic listener for html components. For example, the html contains an img tag with a src attribute and I would like to handle this click on java side without using specific javascript, since I don't have access to the HTML being loaded.
I noticed that Android Studio prints logs into console, so maybe there is a listener for that I can override?
I've tried using the WebView onClick handler, but it is for the component and not its content, so I wasn't able to track the html element which triggered the click to get the src value, for example.
Also, the shouldOverrideUrlLoading method from WebViewClient doesn't work either, since it is just a click and not an url change. :(
"I would like to handle this click on java side without using specific javascript, since I don't have access to the HTML being loaded."
Ah, but you do! You can use [evaluateJavaScript](https://developer.android.com/reference/android/webkit/WebView.html#evaluateJavascript(java.lang.String, android.webkit.ValueCallback)) to run some JavaScript on the page to set up the click handler you want.
I want to use the quick return pattern which is described here:
http://www.androiduipatterns.com/2012/08/an-emerging-ui-pattern-quick-return.html
When i use a webview this webview must have the fullscreen height of the device to implement it correctly. Then i have to inject a paddingTop to the body tag on the html in the webview to get the correct margin/padding from top. But there is a problem if the toolbar isnt shown and the site loads new content with javascript which cant scroll. First there is a ugly white area on the top off the webview and second the toolbar cant get shown because the site cant scroll.
Is there any best practice for this behaviour?
Is the javascript injection the correct way?
In my application I have one Webview and two buttons next and previous. First time load content from database after that I zoom my Webview and change the page using next button then display content but the zooming is stated.
So my question is that how I change a Webview in initial scale?
I used this:
web1.getSettings().setBuiltInZoomControls(true);
and after click on next page used this:
web1.getSettings().setDefaultZoom(ZoomDensity.FAR);
web1.setInitialScale(100);
but no any effects.
Please help me.
Try using web1.getSettings().setLoadWithOverviewMode(true); and web1.getSettings().setUseWideViewPort(true);
I'm trying to mimic the default android Browser app layout, which has a "search_bar" on top and then a "webview" right below it. The user can scroll both items up, all the while the scroll bar only appears to the right of the webview (not both the webview and the search bar).
I've tried putting both the webview and the searchbar into a scrollview, but this shows the scrollbar next to the search_bar.
If you need to mimic the exact layout of default browser have a look at it's source code:
Where can I find Android source code online?
If you need only browser source have a look here:
https://android.googlesource.com/platform/packages/apps/Browser
From what I can see (a quick look at it) it is more complicated layout, but you may start analysing it from:
Browser\res\layout\browser_subwindow.xml
which directly includes WebView. This file is directly loaded by Tab... Go ahaed and analyse it on your own it is pretty simple as it is a regular Android application.
Hope it helps.
I have a web view that is loaded with an HTML that contains links.
when I switch to another activity (say to another tab in a tab
activity) and then switching back to it, the link is surrounded with
an orange rectangle. also happens in the GoogleAdView which really
makes it impossible to view.
Try this to prevent webview from drawing a focus rectangle when it is first focused
webView.getSettings().setNeedInitialFocus(false);
Try webView.setFocusableInTouchMode(false) - it worked for me. Also, read this link if you want to understand what drove me to this solution.
You should take into account though that this solution will make all text input boxes in your webpage unavailable...
Found another solution, but it requires access to the html itself. You need to set the following css property: -webkit-tap-highlight-color:rgba(0,0,0,0); This will not cause the problem with the input boxes.
It seems that the link in the WebView has the focus. Maybe you could avoid it by letting another view request the focus (anotherView.requestFocus();) in onResume() or onStart().