Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView into a Fragment (android.support.v4)

I got a tab menu using a ViewPager. Each tab contains fragments from android.support.v4 package (compatibility with old SDKs). One of the fragment is a WebView (called FragmentWeb) and I want it to stay into the pager layout. The problem is when my WebView is inflated, it runs in fullscreen mode.

Is there a way to keep web browser under my tabs ?

Thank you

My Fragment Class : FragmentWeb.java

public class FragmentWeb extends Fragment {

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View mainView = (View) inflater.inflate(R.layout.fragment_web, container, false);
    WebView webView = (WebView) mainView.findViewById(R.id.webview);
    webView.loadUrl("http://www.google.com");
    return mainView;
}
}

My Fragment's layout : fragment_web.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

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

</LinearLayout>
like image 619
Kyso84 Avatar asked Dec 10 '22 02:12

Kyso84


1 Answers

You can simply adapt the current implementation of WebViewFragment to your needs by replacing:

import android.app.Fragment;

by

import android.support.v4.app.Fragment;

in your own copy of WebViewFragment.java source.

like image 128
leo9r Avatar answered Dec 21 '22 11:12

leo9r