android.webkit.WebView.setLayerType()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(311)

本文整理了Java中android.webkit.WebView.setLayerType()方法的一些代码示例,展示了WebView.setLayerType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebView.setLayerType()方法的具体详情如下:
包路径:android.webkit.WebView
类名称:WebView
方法名:setLayerType

WebView.setLayerType介绍

暂无

代码示例

代码示例来源:origin: sunfusheng/MarqueeView

webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
  settings.setLoadsImagesAutomatically(true); //支持自动加载图片
} else {
  webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
  settings.setLoadsImagesAutomatically(false);

代码示例来源:origin: sunfusheng/StickyHeaderListView

webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
  settings.setLoadsImagesAutomatically(true); //支持自动加载图片
} else {
  webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
  settings.setLoadsImagesAutomatically(false);

代码示例来源:origin: Justson/AgentWeb

webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
  webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

代码示例来源:origin: luili16/UIMocker

@Override
public void setLayerType(int layerType, Paint paint) {
  mWebView.setLayerType(layerType,paint);
}

代码示例来源:origin: stackoverflow.com

wv.setWebViewClient(new WebViewClient() {
     @Override
     public void onPageFinished(WebView view, String url) {
       super.onPageFinished(view, url);
       view.setBackgroundColor(ContextCompat.getColor(context, R.color.transparent));
       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
         view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
       } else {
         view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
       }
     }
   });
   wv.setBackgroundResource(android.R.color.transparent);

代码示例来源:origin: stackoverflow.com

wv.setWebViewClient(new WebViewClient() {
       @Override
       public void onPageFinished(WebView view, String url) {
         super.onPageFinished(view, url);
         view.setBackgroundColor(ContextCompat.getColor(context, R.color.transparent));
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
           view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
         } else {
           view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
         }
       }
     });
     wv.setBackgroundResource(android.R.color.transparent);

代码示例来源:origin: stackoverflow.com

webView.setBackgroundColor(0x00000000);
if (Build.VERSION.SDK_INT >= 11) webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);

this.wv.setWebViewClient(new WebViewClient()
{
  @Override
  public void onPageFinished(WebView view, String url)
  {
    view.setBackgroundColor(0x00000000);
    if (Build.VERSION.SDK_INT >= 11) view.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
  }
});

代码示例来源:origin: stackoverflow.com

public static  class PlaceHolderFragment extends Fragment{

WebView mWebView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {

   View rootView = inflater.inflate(R.layout.fragment_main, container, false);
   mWebView = (WebView) rootView.findViewById(R.id.webview);
   mWebView.getSettings().setJavaScriptEnabled(true);
   mWebView.loadUrl("http://www.google.com");
   mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
   mWebView.setWebViewClient(new HelloWebViewClient());
   return rootView;
}

代码示例来源:origin: stackoverflow.com

WebView wv = (WebView) findViewById(R.id.webView);
 wv.setBackgroundColor(0);
 wv.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
 wv.loadUrl("file:///android_asset/myview.html");

代码示例来源:origin: stackoverflow.com

WebView web = (WebView)findViewById(R.id.webby);
//For avoiding a weird error message
web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

String webContent = "<!DOCTYPE html><html><head><meta charset=\"UTF-8\"><link rel=\"stylesheet\" href=\"style.css\"></head>"
              + "<body><img src='image.png' width=\"100px\"><div class=\"running\">I am a text rendered with INDIGO</div></body></html>";

String internalFilePath = "file://" + getFilesDir().getAbsolutePath() + "/";
web.loadDataWithBaseURL(internalFilePath, webContent, "text/html", "UTF-8", "");

代码示例来源:origin: stackoverflow.com

webView.setBackgroundColor(0x00000000); 
if (Build.VERSION.SDK_INT >= 11) webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);

this.wv.setWebViewClient(new WebViewClient() { 

@Override public void onPageFinished(WebView view, String url) {                
   view.setBackgroundColor(0x00000000); if (Build.VERSION.SDK_INT >= 11) 
   view.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); } });

代码示例来源:origin: stackoverflow.com

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SuppressLint("NewApi")
public static void clearWebViewBackground (final WebView webView) {
  webView.setBackgroundColor(0x00FFFFFF);
  webView.setWebViewClient(new myWebViewClient());
  if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
    webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
  }
}

代码示例来源:origin: stackoverflow.com

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.whatever);

  //make your splash visible here

  WebView browser = (WebView) findViewById(R.id.yourWebView);
  //remove flicker
  browser.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
  browser.setWebViewClient(new WebViewClient() {
    @Override
    public void onPageFinished(WebView view, String url) {
      //make it invisible here
    }
  });

  browser.loadUrl("file:///android_asset/whatever.html");
}

代码示例来源:origin: stackoverflow.com

WebView webViewDisplay;
StringBuffer LoadWEb1;

webViewDisplay = (WebView) findViewById(R.id.WebViewToDisplay);
LoadWEb1 = new StringBuffer();
LoadWEb1.append("<html><body><h1>My First Heading</h1><p>My first paragraph.</p>");
//Sample code to read parameters at run time
String strName = "Test Paragraph";
LoadWEb1.append("<br/><p>"+strName+"</p>");
String result = LoadWEb1.append("</body></html>").toString();
    WebSettings webSettings = webViewDisplay.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webViewDisplay.getSettings().setBuiltInZoomControls(true);
    if (android.os.Build.VERSION.SDK_INT >= 11){
      webViewDisplay.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
      webViewDisplay.getSettings().setDisplayZoomControls(false);
    }

    webViewDisplay.loadDataWithBaseURL(null, result, "text/html", "utf-8",
        null);
    //To load local file directly from assets folder use below code
    //webViewDisplay.loadUrl("file:///android_asset/aboutapp.html");

代码示例来源:origin: stackoverflow.com

WebView myWebView = (WebView) findViewById(R.id.webview1);
 myWebView.getSettings().setBuiltInZoomControls(false);
 myWebView.setVerticalScrollBarEnabled(false);
 myWebView.clearCache(true);
 myWebView.setFocusable(true);
 myWebView.setHorizontalScrollBarEnabled(false);
 myWebView.getSettings().setPluginState(PluginState.ON);
 myWebView.getSettings().setJavaScriptEnabled(true);
 myWebView.getSettings().setAppCacheEnabled(true);
 myWebView.getSettings().setRenderPriority(RenderPriority.HIGH);
 myWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
 myWebView.getSettings().setAllowFileAccess(true);
 myWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
 myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

代码示例来源:origin: stackoverflow.com

WebView text = (WebView) view.findViewById(R.id.webview);
 text.setDrawingCacheEnabled(false);
 WebSettings settings = text.getSettings();
 settings.setDefaultTextEncodingName("utf-8");
 text.setBackgroundColor(Color.TRANSPARENT);
   if (Build.VERSION.SDK_INT >= 11) // Android v3.0+
     try {
     text.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
     } catch (Exception e) {
     }

代码示例来源:origin: marcoscgdev/Licenser

webView.getSettings().setLoadWithOverviewMode(true);
if (Build.VERSION.SDK_INT < 19)
  webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
else webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
if (Build.VERSION.SDK_INT >= 21)
  webView.getSettings().setMixedContentMode(0);

代码示例来源:origin: sakurajiang/RestAPP

public void setMyShowWebView(String url){
  WebSettings webSettings=showWebView.getSettings();
  webSettings.setLoadWithOverviewMode(true);
  webSettings.setUseWideViewPort(true);
  webSettings.setAppCacheEnabled(true);
  webSettings.setJavaScriptEnabled(true);
  webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
  webSettings.setSupportZoom(true);
  if (Build.VERSION.SDK_INT >= 19) {
    showWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
  }
  else {
    showWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
  }
  showWebView.setWebChromeClient(new Chrome());
  showWebView.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
      view.loadUrl(url);
      return true;
    }
  });
  showWebView.loadUrl(url);
}
private class Chrome extends WebChromeClient

代码示例来源:origin: OpenGeeksMe/Android-File-Chooser

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  verifyStoragePermissions(this);
  webView = (WebView) findViewById(R.id.webView);
  webSettings = webView.getSettings();
  webSettings.setAppCacheEnabled(true);
  webSettings.setCacheMode(webSettings.LOAD_CACHE_ELSE_NETWORK);
  webSettings.setJavaScriptEnabled(true);
  webSettings.setLoadWithOverviewMode(true);
  webSettings.setAllowFileAccess(true);
  webView.setWebViewClient(new PQClient());
  webView.setWebChromeClient(new PQChromeClient());
  //if SDK version is greater of 19 then activate hardware acceleration otherwise activate software acceleration
  if (Build.VERSION.SDK_INT >= 19) {
    webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
  } else if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT < 19) {
    webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
  }
  webView.loadUrl("https://en.imgbb.com/");
}

代码示例来源:origin: martykan/webTube

public void setUpWebview() {
  // To save login info
  CookieHelper.acceptCookies(webView, true);
  // Some settings
  WebSettings webSettings = webView.getSettings();
  webSettings.setJavaScriptEnabled(true);
  webSettings.setJavaScriptCanOpenWindowsAutomatically(false);
  webSettings.setAllowFileAccess(false);
  webSettings.setDatabaseEnabled(true);
  String cachePath = mApplicationContext
      .getDir("cache", Context.MODE_PRIVATE).getPath();
  webSettings.setAppCachePath(cachePath);
  webSettings.setAllowFileAccess(true);
  webSettings.setAppCacheEnabled(true);
  webSettings.setDomStorageEnabled(true);
  webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
  webView.setHorizontalScrollBarEnabled(false);
  webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
  webView.setBackgroundColor(Color.WHITE);
  webView.setScrollbarFadingEnabled(true);
  webView.setNetworkAvailable(true);
}

相关文章

WebView类方法