2016-05-30 8 views
1

Ich habe zwei Themen für meine Aktivität erstellt; Hell dunkel. Aber wenn ich eine Änderung im Thema triggle, ändert sich die Farbe der Webseite, die in der Webansicht geladen wird, nicht.So ändern Sie den Hintergrund in der Webansicht

Ich habe dies myWebView.setBackgroundColor(Color.TRANSPARENT); versucht, aber es macht keinen Unterschied. Also, wie würde ich darüber gehen?

Hier ist mein Layout bitte sehen Sie;

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:ads="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <LinearLayout 
     xmlns:night="http://schemas.android.com/apk/res-auto" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
     android:background="@color/ColorPrimary" 
     night:night_background="@color/colorPrimary_n" 
     tools:ignore="MissingPrefix"> 

     <ProgressBar 
      android:id="@+id/progressBar3" 
      style="?android:attr/progressBarStyleHorizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="3dp" 
      android:max="100" 
      android:progressDrawable="@drawable/greenprogress" 
      /> 

     <android.support.v4.widget.SwipeRefreshLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/swiperefresh" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
      <WebView 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/webViewTop" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       night:night_background="@color/colorPrimary_n" 
       android:layout_below="@id/progressBar3"/> 

     </android.support.v4.widget.SwipeRefreshLayout> 

    </LinearLayout> 
    <com.google.android.gms.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_alignParentBottom="true" 
     ads:adSize="BANNER" 
     ads:adUnitId="@string/banner_ad_unit_id"> 
    </com.google.android.gms.ads.AdView> 
</RelativeLayout> 

Antwort

0

Ok so um nach der Suche, fand ich, dass sich die Farbe der Webseite zu ändern, nachdem es geladen hat, CSS-Anpassung erforderlich ist, können keine Einstellungen in Webansicht in Webseite transparent (zumindest machen meine Fall).

2

Sie können es programmatisch wie erreichen unter

webView.getSettings(); 
webView.setBackgroundColor(Color.TRANSPARENT); 

Ich glaube, Sie mit Schichttyp

zu

mWebView.setLayerType (WebView.LAYER_TYPE_SOFTWARE, null) gehen sollte;

VIEL GLÜCK :)

+0

was webView.setBackgroundColor (Color.TRANSPARENT); tut es das, macht es anfangs webview transparent, und am anfang der aktivität kann ich meine themenfarbe sehen, aber nachdem die webseite beginnt zu laden, verschwindet es, und die farbe der webseite findet statt. –

+0

Nop, es funktioniert auch nicht. –

0

Sie können dies in Java versuchen

webView.setBackgroundColor(Color.TRANSPARENT); 
webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); 
+0

Funktioniert nicht :( –

1

try this

WebView synopsis; 
synopsis=(WebView)findViewById(R.id.synopsis); 
synopsis.getSettings(); 
synopsis.setBackgroundColor(Color.TRANSPARENT); 
+0

Danke! Aber ich habe bereits auf Frage geschrieben, dass synopsis.setBackgroundColor (Color.TRANSPARENT); funktioniert nicht. –

0

diesen Code in XML-Put:

android:background="@android:color/transparent" 


<WebView 
    android:id="@+id/MyWebView" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@android:color/transparent" 
    android:scrollbars="none" /> 

und danach Sie gehen einfach zu Java-Code und schreiben dies vor loadURL:

yourWebView.setBackgroundColor(Color.TRANSPARENT); 
+0

Nein, es funktioniert nicht. Vor dem Laden der Webseite bleibt es transparent, aber sobald es lädt, erwirbt es die Farben der Webseite –

Verwandte Themen