Home » Android » Disable address bar in Android webview

Disable address bar in Android webview

Posted by: admin April 10, 2020 Leave a comment

Questions:

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

How to&Answers:

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

Answer:

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

Answer:

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.

Answer:

webview.setWebViewClient(new WebViewClient());  

solved the problem for me..