android - android 4.4.2 中的 webview 卡住

标签 android html android-webview

我有一个应用程序,我正在使用 url 在 Activity 中加载 webview 还有抽屉 这在 android 4.4.2 中是卡住的 , 这在 android 5.0 和 6.0 以后工作正常

根据 android monitor log in freeze case 如下 ,那是在每次滑动或触摸时重复的日志

  • I/View: Touch down dispatch to android.webkit.WebView{42841ec0 VFED..C. .F ...... 0,0-480,666 #7f100075 app:id/web_view}, event = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=248.48233, y[0]=327.48773, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=20907060, downTime=20907060, deviceId=3, source=0x1002 }
    • D/VelocityTracker:无法打开“/dev/touch”(权限被拒绝)
    • D/VelocityTracker:tpd 读取 x 失败:文件编号错误
    • D/VelocityTracker:tpd 读取失败:文件编号错误
    • I/View:润色调度到 android.webkit.WebView{42841ec0 VFED..C。 .F ...... 0,0-480,666 #7f100075 app:id/web_view}, event = MotionEvent { action=ACTION_UP, id[0]=0, x[0]=248.48233, y[0]=327.48773, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0,pointerCount=1,historySize=0,eventTime=20907129, downTime=20907060, deviceId=3, source=0x1002

然后我将 webview 属性设置为

webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setPluginState(PluginState.ON);
    webView.getSettings().setRenderPriority(RenderPriority.HIGH);
    webView.getSettings().setGeolocationEnabled(true);
    webView.getSettings().setPluginState(WebSettings.PluginState.ON);
    webView.getSettings().setAllowFileAccess(true);

我设置了网络客户端

webView.setWebChromeClient(new WebChromeClient() {            

@覆盖 public boolean onShowFileChooser(WebView webView, ValueCallback filePathCallback, FileChooserParams fileChooserParams) { 返回真; } @覆盖 public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { callback.invoke(原点,真,假); } //Android 3.0+ 的 openFileChooser public void openFileChooser(ValueCallback uploadMsg, String acceptType) { } //Android < 3.0 的 openFileChooser public void openFileChooser(ValueCallback uploadMsg) { } //其他Android版本的openFileChooser public void openFileChooser(ValueCallback uploadMsg, 字符串接受类型, 字符串捕获){ openFileChooser(uploadMsg, acceptType); } public boolean onConsoleMessage(ConsoleMessage cm) { onConsoleMessage(cm.message(), cm.lineNumber(), cm.sourceId()); 返回真; } public void onConsoleMessage(String message, int lineNumber, String sourceID) { } });//结束 setWebChromeClient

    webView.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return true;
        }
        @Override

        public void onPageFinished(WebView view, final String url) {

            super.onPageFinished(view, url);
            CookieSyncManager.getInstance().sync();
            Log.i("finished", url);
        }
    });

这是我的xml

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/layMain"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF"
    tools:context=".LandingActivity">

    <WebView
        android:id="@+id/web_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/include"
        android:scrollbarStyle="insideOverlay"
        android:scrollbars="none"
        android:visibility="gone" />
    <ImageView
        android:id="@+id/splash"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:src="@drawable/splash"
        android:visibility="gone" />
    <include
        android:id="@+id/include"
        layout="@layout/bottom_option"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" />
    <FrameLayout
        android:id="@+id/framLay"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone">
    </FrameLayout>
</RelativeLayout>
<LinearLayout
    android:layout_width="300dp"
    android:layout_height="fill_parent"
    android:layout_gravity="end"
    android:background="@color/white"
    android:orientation="vertical">
    <ListView
        android:id="@+id/navdrawer"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:layout_gravity="end"
        android:background="@android:color/white"
        android:choiceMode="singleChoice"
        android:drawSelectorOnTop="false"></ListView>
    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_marginBottom="2dp"
        android:layout_marginTop="2dp"
        android:background="#454545" />
    <ListView
        android:id="@+id/navdrawer2"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:layout_gravity="end"
        android:layout_weight="1"
        android:background="@android:color/white"
        android:choiceMode="singleChoice"
        android:drawSelectorOnTop="false"></ListView>
    <TextView
        android:id="@+id/tvVersion"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="1dp"
        android:gravity="center" />
    <include layout="@layout/listview_bottom" />
</LinearLayout>

最佳答案

Gradle 3.0.0 及以上版本和 compileSdkVersion 26 以上导致此问题...

我的解决方案不是精确的解决方案,但它解决了问题...... 将应用程序 gradle 切换为

classpath 'com.android.tools.build:gradle:2.3.0'

切换模块gradle到

compileSdkVersion 25
buildToolsVersion '25.0.2'

将所有其他 api 更改为最大 25 将解决 frezee 问题。在主要解决方案出现之前,更改这些东西是值得的!

似乎“Kotlin”并不像预期的那样......因为 CPU 需要更多工作

关于android - android 4.4.2 中的 webview 卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44848034/

相关文章:

css - 如何在网页的右侧和左侧对齐页脚文本?

javascript - HTML bootstrap popover 函数

Android Webview 视口(viewport)问题

android - 在 WebView 中显示来自 Google Docs 的文档

android - 在 web View android 中更改 View

android - 如何删除 gradle 库?

android - 三星生物识别技术

android - 如何在 Gradle 中包含不同版本的不同 apk 中的 jar 列表?

android - 使用 Mockito 2 未按需要测试最终类方法

Java.lang.finalize 堆在 hadoop url 解析作业期间变得太大