在我的web-view
应用中,我编写了四个活动,每个活动包含一个web-view
。所有都运行成功,但在api 19的模拟器中运行时没有显示其中一个活动。较低版本没有问题。
左上角显示“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"
/>
logcat的
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.
答案 0 :(得分:0)
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);
}
答案 1 :(得分:0)
这是我发现的,将你的webchromeclient包装在if语句中,因为它似乎与kitkat不兼容。这个解决方案对我有用!