Android WebView- PopUp background is Transparent - android

I have loaded a WebView in my android app:
webView = (WebView)view.findViewById(R.id.webView);
String url = UrlConstants.URL_CITY;
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(url);
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
But every popUp that is of the website has a transparent background as shown:
I've tried many urls as well: One being this
Anyone help will be appreciated. Thanks

I had a similar issue when adding WebView at runtime using addView. Turns out you need to use the addView overload specifying LayoutParams with MATCH_PARENT. Failing to do so would break side menus and pop-up on some web pages. Really nasty bug if you ask me.

Related

Prevent link to be opened in external browser with WebChromeClient

I've developed a small group of .html pages that are stored in a server.
My android app, using a webview with: setWebChromeClient loads these pages.
minSdkVersion 19
targetSdkVersion 24
The problem:
Everytime I need to load a new page, using a link in my .html page, the new page is opened in an external browser.
Url Overriding
I know about the shouldOverrideUrlLoading() method, when we're using the setWebViewClient().
But unfortunately I can't use the normal webview. I need to use the WebChromeClient() because of some feature that only work with this one. (Like the input file)
My doubt is...
How can I override my URL to force them to load inside of the webChromeClient?
I tried this but with no luck:
webView.setWebChromeClient(new WebChromeClient() {
// (...)
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
You can use following code to achieve this.
WebView web = (WebView)findViewById(R.id.web);
WebSettings webSettings = web.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportMultipleWindows(true); // This forces ChromeClient enabled.
web.setWebChromeClient(new WebChromeClient(){
#Override
public void onReceivedTitle(WebView view, String title) {
getWindow().setTitle(title); //Set Activity tile to page title.
}
});
web.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
I was using an embedded mobile web application in an Android App making use of the WebChromeClient class and did not want to fiddle around with recompiling the APK.
While looking for the easiest header(); solution (since the mobile web application is in php) I found out that using:
header("Location: url.php", TRUE, 307);
was a quick fix solution without recompiling the Android app.
This allowed the user to re-direct within the app without calling the web browser externally from my app.
Here is the link to the answer by Arindam Nayak where I got the idea from.

How to replace the default failed img in Android's WebView

If an img tag load failed in webview,it shows a "?" in blue background color.
How can I replace the default img or hide it in Android Code?
I want to hide it in Android Code, because in javascript, I can use onerror or onload events to solve the problem, but in that way, I have to bind events to all img tag, so I want to find a way in Android Code. I guess webview may have some setting or event to do it, but I don't know.
Check this code it may guide you to a solution:
webView.setWebViewClient(new WebViewClient(){
#TargetApi(11)
#Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
return super.shouldInterceptRequest(view, url);
}
};

Add javascript into WebView

I am developing an application where in 1 part I want to add javascript into WebView.. But am not getting how to do it in an appropriate way.. Can anyone pls guide me into this?????
I am doing it like:
wb=(WebView)findViewById(R.id.webView1);
wb.getSettings().setJavaScriptEnabled(true);
wb.getSettings().setPluginState(WebSettings.PluginState.ON);
wb.getSettings().setPluginsEnabled(true);
wb.loadUrl("javascript:<script " ></script> ");
wb.setWebViewClient(new HelloWebViewClient());
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
It was very simple..also without using any javascriptInterface..In my code, Instead writing:
wb.loadUrl("javascript:<script> </script>");
use,
wb.loadDataWithBaseURL(null,"<script> </script>","text/html","utf-8",null);
and its working now :)
Look at these nice tutorials about how to implements javascript in webview in android..
I think its provides you all the information what you needed..
Android WebView
Android WebView, Javascript and CSS
EDIT: Further if your implemented code having any exception or not working then please post that code and exception then here we can help you..

Keeping a webView contained in Android?

Hey everyone! Im pretty new to Android and I have a webView under 2 other widgets on the screen(Or w/e you call it). But when ever I navigate the webView, its changes to full screen and i cant see my other widgets. Ive looked all over Google but couldn't find anything, is there some way I can fix this?
Im using this code to navigate:
webView.loadUrl("http://www.example.com/");
Thank you.
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return true;
}
});
when you do webView.loadUrl("www.example.com") or if there is a redirection when a hyperlink is clicked or something similar, the android device browser is started. I believe you are stuck with this. Try pasting the above code before you call the webView.loadUrl("www.example.com")
What we are essentially doing is asking the webview to load the url, instead of opening it in the device browser.

How to set WebView as non-fullscreen?

I am trying to use a WebView in my Android application. I am creating my webview in code-side (not in XML). My problem is; when I call loadUrl method of webview, the webview goes fullscreen mode. How can I keep the size of the webview for example 200x200 pixels?
If there is any other option instead of webview, of course welcome :)
Thanks,
Quite possibly what you are seeing is not your activity, but the Browser application, because the URL you linked to did a redirect. Use WebViewClient and shouldOverrideUrlLoading() to catch the redirect and send it back to your own WebView.
#Mahtias Lin, please see my code to create and use WebView;
WebView webView = new WebView(this);
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, 416);
WebSettings webSettings = webView.getSettings();
webSettings.setSavePassword(false);
webSettings.setSaveFormData(false);
webSettings.setJavaScriptEnabled(true);
webView.setLayoutParams(p);
webView.loadUrl("http://www.google.com/");
Above code is not set my webview to 416px height.
#CommonsWare, I tried your suggested with following code and amazingly it works, thanks.
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return false;
}
});
But this usage brought some new problems. When I override shouldOverrideURLLoading, the webview displays with no-addressbar, no-navigation (back, forward etc...)?
And also, the webview doenst accept user inputs?
Ok, I am editing my question :)
I searched and I found the following additional set to make webview to able to get inputs;
webView.requestFocus(View.FOCUS_DOWN);
On the other hand, I guess I will create my own back, forward buttons and address-bar for my webview. I will also attach "what happened" to this thread when I create my buttons and address-bar.
Best,
WebView wb=new WebView();
wb.setInitialScale(60);
this is used for set layout of the emulator. 60 means % value. we can use 0% to 100%.
See my reply and comments on
how to show a webview inside an activity in the middle of screen
Apply LayoutParams to your WebView or to the Layout (i.e. LinearLayout) that's surrounding the WebView, if any, i.e. setLayoutParams(LinearLayout.LayoutParams(200, 200));

Categories

Resources