java.lang.Object | ||
↳ | com.neomades.ui.View | |
↳ | com.neomades.ui.WebView |
A View that displays web pages.
This class is the basis upon which you can roll your own web browser or
simply display some online content within your Screen. It includes methods to
navigate forward and backward through a history, zoom in and out, perform
text searches and more. A WebView
could load an URL with the
loadURL(String)
method or a part of HTML code with the
loadHTML(String, String, String)
method.
A WebView
will enforce a MATCH_PARENT stretch mode in both
directions.
To use this class, the WEB_VIEW
permission must be declared in
the URS file.
WebView
connections, like other HTTP connections in the
application, must follow the ATS requirements:
If the back end server the WebView
must contact is outside of
your scope (a third party server for example), the ATS requirements can be
bypassed by configuring the URS of the project. However, in that case, you
will have to justify it in iTunes Connect when the application will be
prepared for publication and Apple may reject the application.
Full documentation about ATS and network security are available at NeoMAD documentation.
By default, a WebView provides no browser-like widgets, does not enable JavaScript and web page errors are ignored.
XML Attributes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Attribute Name | Related Method | Description | |||||||||
horizontalScroll | setHorizontalScroll(boolean) | If the scrollview could scroll horizontally | |||||||||
openUrlEnabled | setOpenURLEnabled(boolean) | ||||||||||
padding | setPadding(int) | eg: 10dp or 10 (dp is the default unit) | |||||||||
paddingBottom | setPaddingBottom(int) | eg: 10dp or 10 (dp is the default unit) | |||||||||
paddingLeft | setPaddingLeft(int) | eg: 10dp or 10 (dp is the default unit) | |||||||||
paddingRight | setPaddingRight(int) | eg: 10dp or 10 (dp is the default unit) | |||||||||
paddingTop | setPaddingTop(int) | eg: 10dp or 10 (dp is the default unit) | |||||||||
readOnly | setReadOnly(boolean) | If the text inside is not editable | |||||||||
textZoom | setTextZoom(int) | ||||||||||
verticalScroll | setVerticalScroll(boolean) | If the scrollview could scroll vertically | |||||||||
zoomEnabled | setZoomEnabled(boolean) |
[Expand]
Inherited XML Attributes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
WebView() |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
boolean |
canGoBack()
Returns if this
WebView can go back in the history. | ||||||||||
boolean |
canGoForward()
Returns if this
WebView can go forward in the history. | ||||||||||
void |
clearCache()
Clears the cache of the WebView.
| ||||||||||
void |
clearCookies()
Clears all the stored cookie.
| ||||||||||
List<HttpCookie> |
getCookies()
Gets the cookies of the WebView for the current URL.
| ||||||||||
void |
goBack()
Goes back in the history of this WebView.
| ||||||||||
void |
goForward()
Goes forward in the history of this WebView.
| ||||||||||
void |
loadHTML(String html, String mimeType, String baseURL)
Loads the given data into this WebView using a 'base' scheme URL.
| ||||||||||
void |
loadURL(String url)
Loads the given URL.
| ||||||||||
void |
reload()
Reloads the current URL.
| ||||||||||
void |
setCookiePolicy(CookiePolicy policy)
Sets the cookie policy of the Webview.
| ||||||||||
void |
setHorizontalScroll(boolean enabled)
Sets if this
WebView should display the horizontal scrollbar
when scrolling. | ||||||||||
void |
setOpenURLEnabled(boolean openUrlEnabled)
Sets if a click on a link should open the page in this WebView or in the
browser.
| ||||||||||
void |
setPadding(int leftDp, int topDp, int rightDp, int bottomDp)
Has no effect on WebView.
| ||||||||||
void |
setPadding(int uniformPaddingDp)
Has no effect on WebView.
| ||||||||||
void |
setPaddingBottom(int paddingBottomDp)
Has no effect on WebView.
| ||||||||||
void |
setPaddingLeft(int paddingLeftDp)
Has no effect on WebView.
| ||||||||||
void |
setPaddingRight(int paddingRightDp)
Has no effect on WebView.
| ||||||||||
void |
setPaddingTop(int paddingTopDp)
Has no effect on WebView.
| ||||||||||
void |
setReadOnly(boolean readOnly)
Sets this
WebView in read-only mode. | ||||||||||
void |
setTextZoom(int textZoom)
By default, this property is
100 %. | ||||||||||
void |
setVerticalScroll(boolean enabled)
Sets if this
WebView should display the vertical scrollbar when
scrolling. | ||||||||||
void |
setZoomEnabled(boolean enabled)
Sets this
WebView can zoom-in or zoom-out content. | ||||||||||
void |
stopLoading()
Stops the current load.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void |
onProgressChanged(WebView view, int progress)
Override this method in order to listen the loading progress.
| ||||||||||
boolean |
shouldOverrideUrlLoading(WebView webView, String url)
Give the host application a chance to take over the control when a new URL is
about to be loaded in the current WebView.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() |
If the scrollview could scroll horizontally
Returns if this WebView
can go back in the history.
Returns if this WebView
can go forward in the history.
Clears the cache of the WebView. Does not necessarily clears the cookies. Use
clearCookies()
to clear the cookies.
Clears all the stored cookie.
On iOS this method does not work on simulator.
Gets the cookies of the WebView for the current URL.
On Android only the name and the value of the headers are returned.
Loads the given data into this WebView using a 'base' scheme URL.
The 'base' scheme URL formed by this method uses the default US-ASCII charset. If you need need to set a different charset, you should form a 'base' scheme URL which explicitly specifies a charset parameter in the mediatype portion of the URL and call loadUrl(String) instead. Note that the charset obtained from the mediatype portion of a data URL always overrides that specified in the HTML or XML document itself.
mimeType
parameter is
not used on the iOS
platform.html | HTML code |
---|---|
mimeType | "text/html" for example. If null, default to "text/html". |
baseURL | base URL to use to resolve URL links into HTML code. Can be null |
NullPointerException | if the html parameter is null |
---|
Loads the given URL.
url | the URL of the resource to load |
---|
NullPointerException | if the url parameter is null |
---|
Reloads the current URL.
Sets the cookie policy of the Webview. By default it is
ACCEPT_ORIGINAL_SERVER
.
policy | the cookie policy to set |
---|
Sets if this WebView
should display the horizontal scrollbar
when scrolling.
By default, this property is true
.
Sets if a click on a link should open the page in this WebView or in the browser.
By default, this property is false
.
This property is used if shouldOverrideUrlLoading(WebView, String)
returns false.
openUrlEnabled | if true the link will be opened in the browser, else it will be opened in this WebView |
---|
Has no effect on WebView.
leftDp | the left padding (in dp) |
---|---|
topDp | the top padding (in dp) |
rightDp | the right padding (in dp) |
bottomDp | the bottom padding (in dp) |
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Has no effect on WebView.
uniformPaddingDp | the padding to set on each side (in dp). |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Has no effect on WebView.
paddingBottomDp | value of the bottom padding (in dp) |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Has no effect on WebView.
paddingLeftDp | value of the left padding (in dp) |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Has no effect on WebView.
paddingRightDp | value of the right padding (in dp) |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Has no effect on WebView.
paddingTopDp | value of the top padding (in dp) |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Sets this WebView
in read-only mode. The use cannot click over
links or buttons.
By default, this property is false
.
By default, this property is 100
%.
In iOS, setting a zoom has no effect.
Sets if this WebView
should display the vertical scrollbar when
scrolling.
By default, this property is true
.
Sets this WebView
can zoom-in or zoom-out content.
By default, this property is true
.
Stops the current load.
Override this method in order to listen the loading progress.
When the loading starts, the first progress value to be sent to this callback may not be 0, this is platform implementation dependent.
When the loading finishes the last progress value is always 100.
view | this Webview |
---|---|
progress | between a progress percent value always between 0 and 100 |
Give the host application a chance to take over the control when a new URL is about to be loaded in the current WebView.
webView | the WebView that loads the new URL |
---|---|
url | the URL to be loaded |