49

How do disable and hide the address bar from a WebView?

Jeff Lamb
  • 5,755
  • 4
  • 37
  • 54
Jono
  • 17,341
  • 48
  • 135
  • 217

5 Answers5

64

There is no address bar in a WebView.

If you think you have a WebView, and you see an address bar, that is not your WebView. Rather, you are looking at the Browser application. Most likely, the URL you told the WebView to load did a redirect, and you did not intercept that redirect using a WebViewClient and shouldOverrideURLLoading().

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • browser application? i did not call an intent to launch the browser application. i basically used a xml layout with just a single webview that fills the screen an i simple call LoaUrl to that webview. followed this example from the sdk http://developer.android.com/reference/android/webkit/WebView.html – Jono Nov 09 '10 at 20:45
  • 2
    @jonney: As I wrote, most likely, the URL you told the `WebView` to load did a redirect, and you did not intercept that redirect using a `WebViewClient` and `shouldOverrideURLLoading()`. A redirect or click on a link will load the resulting URL in the user's choice of browser, unless you use `WebViewClient` to change that behavior. – CommonsWare Nov 09 '10 at 21:32
  • the address given in the android.com site is "google.com" when you go to google.com it redirects to google.lk :D datz why I see address bar.. Now I get it.. thanks a lot. – Jay Mayu Jan 31 '11 at 17:36
  • 1
    more info here on catching redirects http://stackoverflow.com/questions/8273991/webview-shouldinterceptrequest-example – giorgio79 Jan 17 '14 at 14:21
48

Adding myView.setWebViewClient(new WebViewClient()); disabled the address bar for me.

import android.webkit.WebView;
import android.webkit.WebViewClient;

...

WebView myView = findViewById(R.id.myExampleView);
myView.setWebViewClient(new WebViewClient());
myView.getSettings().setJavaScriptEnabled(true);
myView.loadUrl("https://www.stackoverflow.com");

XML Snippet

<WebView android:id="@+id/myExampleView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true"
    android:gravity="center" />

source: (Japanese site): http://www.techdoctranslator.com/android/webapps/webview

Black
  • 18,150
  • 39
  • 158
  • 271
stingraze
  • 481
  • 4
  • 2
26

Finally I Try with this. Its worked for me..

Here is the working code

private WebView webview ;   
@Override

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ebook);

    //webview use to call own site
    webview =(WebView)findViewById(R.id.webView);

    webview.setWebViewClient(new WebViewClient());          
    webview .getSettings().setJavaScriptEnabled(true);
    webview .getSettings().setDomStorageEnabled(true);      
    webview.loadUrl("http://www.google.com"); 
}

and your entire main.xml(res/layout) look should like this:

<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    />

don't go to add layouts.

King of Masses
  • 18,405
  • 4
  • 60
  • 77
SahanS
  • 675
  • 3
  • 9
  • 21
18
webview.setWebViewClient(new WebViewClient());  

solved the problem for me..

Amnesh Goel
  • 2,617
  • 3
  • 28
  • 47
1

Kotlin code as following

myWebView.setWebViewClient(WebViewClient())