Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fullscreen WebView Android

WebView in my app shows as window, but I want it be fullscreen! Here is screenshort of it: not fullscreen

Here is my code:

public class DockViewerActivity extends Activity {

    private WebView mWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mWebView = new WebView(this);
        setContentView(mWebView);
        mWebView.loadUrl("file:///android_asset/1.html");

        Toast.makeText(this, getString(R.string.loading), Toast.LENGTH_LONG).show();
    }
}
like image 567
Coma White Avatar asked Jan 30 '26 03:01

Coma White


1 Answers

XML

set the height and width to match_parent like below:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/conrainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

    <WebView
         android:id="@+id/webview"
         android:layout_width="match_parent "
         android:layout_height="match_parent "/>

</RelativeLayout>

Activity::

to remove the status bar you have to use:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);

to remove titlebar,you have to use:

requestWindowFeature(Window.FEATURE_NO_TITLE); 

both of the above features you have to set before set your content view like below i am doing:

@Override
protected void onCreate(Bundle savedInstanceState) {
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.base_screen);
}

if you Create webView programtically then set the height, width to match_parent like:

LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
 mWebView .setLayoutParams(layoutParams);

and its done now!! #cheers!!

like image 71
Pankaj Arora Avatar answered Feb 01 '26 15:02

Pankaj Arora