JavaScript没有在4.4 +上工作,这是Android WebView的错误?

时间:2017-05-01 15:38:07

标签: android webview

此js代码" javascript:document.getElementById(' display-name')。value =' 123456';"工作在4.3和更低是好的,但在4.4上面是坏的!

4.4 upper显示带有' 123456'

的空白页面
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        WebView webView = (WebView) findViewById(R.id.webView);
        webView.loadUrl("https://stackoverflow.com/users/signup");
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                // this line work on 4.3 and lower is good
                // but on 4.4 upper is bad!
                view.loadUrl("javascript:document.getElementById('display-name').value='123456';");
            }
        });
        WebSettings settings = webView.getSettings();
        // use firefox agent
        settings.setUserAgentString("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0");
        settings.setJavaScriptEnabled(true);
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
    }
}
顺便说一下......像这样的logcat信息 "找不到类' android.graphics.drawable.RippleDrawable',从方法android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering"中引用。 发生了什么事?我不用任何方式使用它们...... 我将AppCompatActivity更改为Activity.this错误消失了......

0 个答案:

没有答案