Android api级别19中未显示webview

Android api级别19中未显示webview,android,webview,Android,Webview,在我的webview应用程序中,我对四个活动进行了编码,每个活动包含一个webview。所有活动都已成功运行,但其中一个活动在api 19的emulator中运行时未显示。较低版本没有问题 它在左上角显示“165px” 代码如下: package com.example.samworkshops; import android.os.Bundle; import android.os.SystemClock; import android.annotation.SuppressLint; im

在我的
webview
应用程序中,我对四个活动进行了编码,每个活动包含一个
webview
。所有活动都已成功运行,但其中一个活动在api 19的emulator中运行时未显示。较低版本没有问题

它在左上角显示“165px”

代码如下:

package com.example.samworkshops;

import android.os.Bundle;
import android.os.SystemClock;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class Admin extends Activity {

private WebView webView;
final Activity activity = this;


@SuppressLint("SetJavaScriptEnabled")
@Override
public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        this.getWindow().requestFeature(Window.FEATURE_PROGRESS);

        setContentView(R.layout.activity_admin);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

        webView = (WebView)findViewById(R.id.webView4);
        webView.requestFocusFromTouch();

        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.loadUrl("http://app.samworkshops.org/PasswordProtect.aspx");

        webView.setVisibility(View.INVISIBLE);

        webView.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress)
            {
                activity.setTitle("Loading...");
                activity.setProgress(progress * 100);

                if(progress == 100)
                    activity.setTitle(R.string.title_activity_admin);
            }
        });
        //webView.setBackgroundColor(Color.parseColor("#ec1661"));
        webView.setInitialScale(95);

        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
            {
                // Handle the error
            }

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


            @Override  
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                StringBuilder builder = new StringBuilder("");
                builder.append("javascript:document.getElementById('Button2').style.visibility = 'hidden';");
                builder.append("javascript:document.getElementById('Button2').style.display    = 'none'  ;");
                builder.append("javascript:document.getElementById('atxt1').style.position = 'relative'  ;");
                builder.append("javascript:document.getElementById('atxt1').style.right    = '225px'  ;");
                builder.append("javascript:document.getElementById('atxt1').style.bottom    = '165px'  ;");

                builder.append("javascript:document.getElementById('atxt2').style.position = 'relative'  ;");
                builder.append("javascript:document.getElementById('atxt2').style.right    = '225px'  ;");
                builder.append("javascript:document.getElementById('atxt2').style.bottom    = '165px'  ;");

                builder.append("javascript:document.getElementById('atxt3').style.position = 'relative'  ;");
                builder.append("javascript:document.getElementById('atxt3').style.right    = '225px'  ;");
                builder.append("javascript:document.getElementById('atxt3').style.bottom    = '165px'  ;");

                builder.append("javascript:document.getElementById('atxt4').style.position = 'relative'  ;");
                builder.append("javascript:document.getElementById('atxt4').style.right    = '225px'  ;");
                builder.append("javascript:document.getElementById('atxt4').style.bottom    = '165px'  ;");

                builder.append("javascript:document.getElementById('txtUsername').style.position = 'relative'  ;");
                builder.append("javascript:document.getElementById('txtUsername').style.right    = '225px'  ;");
                builder.append("javascript:document.getElementById('txtUsername').style.bottom    = '165px'  ;");

                builder.append("javascript:document.getElementById('txtPassword').style.position = 'relative'  ;");
                builder.append("javascript:document.getElementById('txtPassword').style.right    = '225px'  ;");
                builder.append("javascript:document.getElementById('txtPassword').style.bottom    = '165px'  ;");

                builder.append("javascript:document.getElementById('DropDownList1').style.position = 'relative'  ;");
                builder.append("javascript:document.getElementById('DropDownList1').style.right    = '225px'  ;");
                builder.append("javascript:document.getElementById('DropDownList1').style.bottom    = '165px'  ;");


                builder.append("javascript:document.getElementById('Button3').style.position = 'relative'  ;");             
                builder.append("javascript:document.getElementById('Button3').style.right    = '185px'  ;");
                builder.append("javascript:document.getElementById('Button3').style.bottom    = '165px'  ;");




                view.loadUrl(builder.toString());
                webView.setVisibility(View.VISIBLE);
                SystemClock.sleep(1000);

            }  


        });

    }
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // Check if the key event was the Back button and if there's history
    if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
        webView.goBack();
        return true;
    }
    // If it wasn't the Back key or there's no web page history, bubble up to the default
    // system behavior (probably exit the activity)
    return super.onKeyDown(keyCode, event);
}

}
activity_event.xml

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webView4"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:windowSoftInputMode="adjustResize"
/>
这应该行得通,将API 19的所有“加载url”替换为“evaluateJavascript”
if(android.os.Build.VERSION.SDK_INT<19){
v、 加载url(url);
}否则{
v、 evaluateJavascript(url,null);
}

这就是我发现的,将webchromeclient封装在if语句中,因为它似乎与kitkat不兼容。这个解决方案对我有效

您是否在模拟器中启用了硬件GL加速?它在物理设备上工作吗?emulator中的OpenGL ES 2.0支持可能存在一些问题。
02-01 06:54:31.025: E/chromium(1436): [ERROR:gl_surface_egl.cc(620)] GLSurfaceEGL::InitializeOneOff failed.
02-01 06:54:31.035: E/chromium(1436): [ERROR:gl_surface_egl.cc(153)] No suitable EGL configs found.
02-01 06:54:31.035: E/chromium(1436): [ERROR:gl_surface_egl.cc(620)] GLSurfaceEGL::InitializeOneOff failed.
02-01 06:54:31.035: E/chromium(1436): [ERROR:gpu_info_collector.cc(86)] gfx::GLSurface::InitializeOneOff() failed
02-01 06:54:31.025: E/chromium(1436): [ERROR:gl_surface_egl.cc(153)] No suitable EGL configs found.
  This should work ,replace all "load url" with "evaluateJavascript" for API 19 



 if (android.os.Build.VERSION.SDK_INT < 19) {
                        v.loadUrl(url);
                    } else {
                        v.evaluateJavascript(url,null);
                    }