Puedes crear una clase para el fragmento donde tendras el webview. Te dejo un ejemplo que he probado a ver si te sirve.
WebviewFragment.java:
public class WebviewFragment extends Fragment {
WebView webView;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_layout,container);
webView = (WebView)view.findViewById(R.id.webView1);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("https://es.stackoverflow.com/");
return view;
}
}
fragment_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
MainActivity.java:
public class MainActivity extends AppCompatActivity {
WebviewFragment fragment;
android.app.FragmentManager fragmentManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fragmentManager = getFragmentManager();
fragment = (WebviewFragment)
fragmentManager.findFragmentById(R.id.fragment);
}
}