2017-08-03 57 views
0

我在我的活动中插入了webview,但插入的webview的导航抽屉工作不正常(每当我点击它时,它都会一直加载)。其他一切工作正常。无法打开插入的webview的导航抽屉

This is the image which i am talking about

下面给出的是在我所插入的WebView的XML代码:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/white" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/activity_education" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/white_overlay" 
     android:orientation="vertical" 

     tools:context="com.aaryanapps.mdconnect.ui.activity.EducationActivity"> 

     <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:theme="@style/AppTheme.AppBarOverlay"> 

      <include layout="@layout/dashboard_actionbar" /> 

     </android.support.design.widget.AppBarLayout> 

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_below="@+id/my_awesome_toolbar"> 


      <WebView 
       android:id="@+id/education_webView" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:background="@color/white" /> 

     </RelativeLayout> 

    </LinearLayout> 

    <include layout="@layout/navigation_drawer_view" /> 

</android.support.v4.widget.DrawerLayout> 

下面给出的是Java代码加入web视图:

package com.aaryanapps.mdconnect.ui.activity; 

import android.os.Bundle; 
import android.webkit.URLUtil; 
import android.webkit.WebView; 
import android.webkit.WebViewClient; 

import com.aaryanapps.mdconnect.R; 

public class EducationActivity extends NavigationActivity { 

    private WebView _webview; 

    private boolean _webview_loaded = false; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

     mToolbarTitleText = "Education"; 
     super.onCreate(savedInstanceState); 

     _webview = (WebView) findViewById(R.id.education_webView); 
     _webview.setWebViewClient(new WebViewClient()); 

     if (!_webview_loaded) { 
      updateViews(); 
     } 

    } 


    protected void prepareInit() { 

     content_view = R.layout.activity_education; 
    } 

    private void updateViews() { 

     if (null == _webview || _webview_loaded) { 
      return; 
     } 

     _webview_loaded = true; 

     String desc = "http://www.google.com"; 
     //General.replaceNull(cad.getlong_description()); 
     if (URLUtil.isHttpUrl(desc) || URLUtil.isHttpsUrl(desc)) { 
      //Load the url in the webview. 
      _webview.loadUrl(desc); 
      return; 
     } 

     _webview.getSettings().setJavaScriptEnabled(true); 
     _webview.loadData(desc,"text/html", "UTF-8"); 


    } 
} 

回答

0

试图把这在另一个布局中,并将其包含在导航布局的顶部。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/activity_education" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/white_overlay" 
     android:orientation="vertical" 

     tools:context="com.aaryanapps.mdconnect.ui.activity.EducationActivity"> 

     <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:theme="@style/AppTheme.AppBarOverlay"> 

      <include layout="@layout/dashboard_actionbar" /> 

     </android.support.design.widget.AppBarLayout> 

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_below="@+id/my_awesome_toolbar"> 


      <WebView 
       android:id="@+id/education_webView" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:background="@color/white" /> 

     </RelativeLayout> 

    </LinearLayout> 
+0

请问您能更具体些吗? @vryin和耶,“试着把它放在另一个布局中”,我们必须创建另一个布局资源文件或者只是将Linearlayout更改为RelativeLayout? – Msavaj

+0

我的意思是“试着把它放在另一个布局中”意味着它是你自己的代码,你没有注意到相似之处吗?是的,你必须创建另一个布局资源文件,因为它似乎彼此有冲突。 – Bryan

+0

无法使用@vryin – Msavaj