WebView is not filling the whole screen of device or emulator

情到浓时终转凉″ 提交于 2019-11-29 19:06:40

问题


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.


回答1:


just ad in manifest the following code:

>

<supports-screens android:smallScreens="true"
    android:normalScreens="true" android:largeScreens="true"
    android:anyDensity="true" />



回答2:


mWebView.setWebChromeClient(new MyWebChromeClient());

remove this java code from your activity.java file then se,




回答3:


just remove the padding from your layout...



来源:https://stackoverflow.com/questions/5739353/webview-is-not-filling-the-whole-screen-of-device-or-emulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!