2014-02-01 4 views
1

В моем приложении web-view я закодировал четыре действия, каждый из которых содержит один web-view. Все работают успешно, но одно из действий не отображается во время работы в эмуляторе api 19. Нет проблем с более низкими версиями.webview не отображается на уровне 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. 
+1

У вас есть аппаратное ускорение GL в эмуляторе? Работает ли он на физическом устройстве? Поддержка OpenGL ES 2.0 в эмуляторе может иметь некоторые проблемы. – fadden

ответ

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); 
        } 
0

Это то, что я обнаружил, обернуть webchromeclient в если заявление, поскольку, похоже, не t o быть совместимым с kitkat. Это решение работало для меня!

Смежные вопросы