我已经在我的活动中插入了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>
以下是添加webview的java代码:
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 :(得分: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>