我的应用程序没有在我们的Jelly Bean(htc evo 4g lte)上显示它的webview,但是在api 16及更低版本的大多数情况下运行正常。过去几个小时我一直在网上看看,还没有找到一个满意的答案,为什么我的webview不会出现在4.2手机上。
这是MainActivity,
package com.example;
import java.net.URL;
import android.R.color;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.LinearLayout;
import com.example.*;
import com.google.ads.*;
public class MainActivity extends Activity {
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Request an ad
AdView ad = (AdView) findViewById(R.id.adView);
ad.loadAd(new AdRequest());
Button myButton = (Button) findViewById(R.id.button1);
myButton.setBackgroundColor(0);
myButton.setBackgroundResource(color.darker_gray);
myButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/html");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml("<p>This is the text that will be shared.</p>"));
startActivity(Intent.createChooser(sharingIntent,"Share using"));
}
});
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(webView, DISPLAY_SERVICE);
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(true);
webView.loadUrl("http://example.com");
WebView myWebView = (WebView) findViewById(R.id.webView1);
webView.setBackgroundColor(Color.parseColor("#000000"));
WebView webView=(WebView)this.findViewById(R.id.webView1);
Intent intent = new Intent(Intent.ACTION_VIEW);
webView.getSettings().setAllowFileAccess(true);
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
myWebView.onPause();
webView.getSettings().setSupportZoom(false);
webView.getSettings().setDisplayZoomControls(false);
WebView myWebView1 = (WebView) findViewById(R.id.webView1);
myWebView1.setWebViewClient(new WebViewClient());
webView.canGoBack();
WebSettings config = webView.getSettings();
config.setJavaScriptEnabled(true);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (webView != null && (keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
webView.goBack();
return true;
}
return true;
}
}