Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView is not filling the whole screen of device or emulator

I am developing an android application which loads a web application when started. To achieve the purpose I am using webview control. I want my webview to be displayed full screen so that it will give native feel to the users. I tried all the methods to display webthview full screen but nothing is working. I dont know what I am missing. I need help on that. Below I am posting the code snippets that I tried also attached screenshots that shows how webview is displaying on emulator and mobile as well.

Method 1: Tried with simple basic code

    webbrowser.setWebViewClient(new MyWebViewClient());
    webbrowser.getSettings().setJavaScriptEnabled(true);
    webbrowser.loadUrl("http://google.com");

private class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }

Method 2: Tried setting theme as full screen in manifest file

        <application android:icon="@drawable/icon" 
    android:label="@string/app_name"
  android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

Method 3: Tried doing it using code

//Full screen
requestWindowFeature(Window.FEATURE_NO_TITLE); 
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
WindowManager.LayoutParams.FLAG_FULLSCREEN);

Method 4: Tried with ChromeClient

mWebView.setWebChromeClient(new MyWebChromeClient());
mWebView.addJavascriptInterface(new DemoJavaScriptInterface(), "demo");
mWebView.loadUrl("http://google.com/");

Method 5: Tried just defining webview without layout in main.xml

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview_compontent"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scrollbars="none"
/>

Method 6: Also tried with relative layout by aligning webview edges to parent

Nothing worked for me. The device I am testing with is samsung galaxy tab and emulator is Android 2.3.3. In 7 inch galaxy tab it is showing up in the middle and on four sides there are blank spaces. Whereas in emulator its leaving space at the bottom.

I really appreciate if someone can guide me on this.

like image 746
Raju Avatar asked Apr 21 '11 03:04

Raju


People also ask

How can I improve my WebView performance?

I read about how to increase performance of WebView by implementing Caching web resources like JS, CSS and image files. You can also static resources in your native application, and by intercepting the Resource requests you can override the default behaviour of WebView.

How do I zoom out in WebView Android?

webview. getSettings(). setLoadWithOverviewMode(true); This will cause the webview to be zoomed out initially.

What can I use instead of WebView?

Alternatives to WebView If you want to send users to a mobile site, build a progressive web app (PWA). If you want to display third-party web content, send an intent to installed web browsers. If you want to avoid leaving your app to open the browser, or if you want to customize the browser's UI, use Custom Tabs.

How do I disable scrolling in WebView?

If you put a WebView in a ScrollView, set the android:isScrollContainer attribute of the WebView to "false" rather than setting android:scrollbars to "none". This has the effect of completely disabling the scroll handling of the webview and allows it to expand according to its content.


1 Answers

just ad in manifest the following code:

>

<supports-screens android:smallScreens="true"
    android:normalScreens="true" android:largeScreens="true"
    android:anyDensity="true" />
like image 180
Hanry Avatar answered Sep 20 '22 23:09

Hanry