Webview未在片段Android

时间:2017-03-31 12:24:06

标签: android android-fragments android-webview

我正在尝试在我的webview里面加载网站片段,但网页没有打开。我已经添加了INTERNET权限。

我也添加了片段代码。 MainActivity.java& activity_main.xml中

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View v=inflater.inflate(R.layout.maps,container,false);

        webView = (WebView) v.findViewById(R.id.webViewMap);
        String url = "http://www.google.co.in/";
        webView.setWebViewClient(new WebViewClient());
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl(url);

        return v;
    }

Xml文件

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

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

activity_main.xml中

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</FrameLayout>

MainActivity.java

mBottomBar.setItemsFromMenu(R.menu.menu_nav, new OnMenuTabClickListener() {
            @Override
            public void onMenuTabSelected(@IdRes int i) {
               if(i==R.id.home_id)
               {
                  HomeFragment f=new HomeFragment();
                   getSupportFragmentManager().beginTransaction().replace(R.id.frame,f).commit();
               }

                else if(i==R.id.map_id)
                {
                    MapFragment f=new MapFragment();
                    getSupportFragmentManager().beginTransaction().replace(R.id.frame,f).commit();

                }

                else if(i==R.id.stat_id)
                {
                    StatFragment f=new StatFragment();
                    getSupportFragmentManager().beginTransaction().replace(R.id.frame,f).commit();
                }
                else if(i==R.id.dash_id)
                {
                    DashFragment f=new DashFragment();
                    getSupportFragmentManager().beginTransaction().replace(R.id.frame,f).commit();
                }
            }

            @Override
            public void onMenuTabReSelected(@IdRes int i) {

            }

        });

0 个答案:

没有答案