2014-05-24 4 views
4

Récemment, j'implémente l'application web sur Android. Je veux faire la couleur de fond de webview Transparent. En recherchant, j'ai trouvé deux lignes pour Webview.Comment rendre l'arrière-plan Android Webview transparent à KITKAT (4.4)

newWebView.setBackgroundColor(0x00000000);     
newWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 

Cela fonctionne pour Android version 4.0 ~ 4.3, mais ne fonctionne pas pour 4.4 KITKAT.

J'ai juste un fond blanc. Addtionally, quand je définir la couleur d'arrière-plan, noir, illustré ci-dessous:

newWebView.setBackgroundColor(Color.BLACK); 

Aussi je vis-fond blanc. Y a-t-il quelqu'un qui connaît la solution?

+0

Aller à cette [http: // stackoverflow. com/questions/20675554/webview-rendu-question-en-android-kitkat] (http://stackoverflow.com/questions/20675554/webview-rendering-issue-in-android-kitkat) –

+0

cet affichage ne fonctionne pas pour moi :( – Stern

+0

essayez de définir l'étiquette alpha de la webview elle-même Je ne sais pas si elle existe bien –

Répondre

4

Cela pourrait vous aider

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

Source: http://premius.net/blog/andoid/118-android-webview-transparent-background-for-android-2-3-and-4-x.html

+1

ça marche pour 4.3 et ci-dessous, mais pas pour 4.4 (kitkat) :( – Stern

1

œuvres pour Android 6 (pour moi), voir réponse précédente

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

aussi vous pouvez essayer d'ajouter wv.setWebChromeClient – VKDev

Questions connexes