开发者

WebView is not filling the whole screen of device or emulator

开发者 https://www.devze.com 2023-02-28 06:45 出处:网络
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

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 开发者_如何学JAVAdisplaying 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.


just ad in manifest the following code:

>

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


mWebView.setWebChromeClient(new MyWebChromeClient());

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


just remove the padding from your layout...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号