Java Webview未显示所需结果
正在尝试实现webview。但除了白色屏幕外,什么也没有出现 这个片段包含这个Java Webview未显示所需结果,java,android,android-fragments,android-webview,Java,Android,Android Fragments,Android Webview,正在尝试实现webview。但除了白色屏幕外,什么也没有出现 这个片段包含这个 View view; private WebView webView; @SuppressLint("SetJavaScriptEnabled") @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view;
private WebView webView;
@SuppressLint("SetJavaScriptEnabled")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_nav, container, false);
webView = (WebView) view.findViewById(R.id.webview_nav);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadUrl("https://google.com");
// Force links and redirects to open in the WebView instead of in a browser
webView.setWebViewClient(new WebViewClient());
return view;
}
像这样从mainactivity调用片段
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragment_nav fragment_nav = new fragment_nav();
fragmentTransaction.replace(R.id.frame_layout, fragment_nav);
fragmentTransaction.commit();
片段活性
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/Black"
>
<WebView
android:id="@+id/webview_nav"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
请告诉我哪里出了问题。因为当我在另一个项目中做同样的事情时,它是有效的。但不是在这个项目中。你想做什么?因为实现webview的方法很少,所以我尝试在单击导航按钮后立即使用webview显示google地图