Jono
Jono

Reputation: 18108

Disable address bar in Android webview

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

Upvotes: 49

Views: 61945

Answers (5)

Mehmet Ali kandemir
Mehmet Ali kandemir

Reputation: 51

Kotlin code as following

myWebView.setWebViewClient(WebViewClient())

Upvotes: 1

stingraze
stingraze

Reputation: 481

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

Upvotes: 48

webview.setWebViewClient(new WebViewClient());  

solved the problem for me..

Upvotes: 18

SahanS
SahanS

Reputation: 675

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.

Upvotes: 26

CommonsWare
CommonsWare

Reputation: 1006644

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().

Upvotes: 64

Related Questions