Android 如何在webview中更改背景
我为我的活动创建了两个主题;亮/暗。但当我触发主题改变时,webview中加载的网页的颜色并没有改变 我试过这个Android 如何在webview中更改背景,android,webview,background-color,Android,Webview,Background Color,我为我的活动创建了两个主题;亮/暗。但当我触发主题改变时,webview中加载的网页的颜色并没有改变 我试过这个myWebView.setBackgroundColor(Color.TRANSPARENT) 但这没什么区别。那么,我该怎么做呢 这是我的布局图,请看一下 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com
myWebView.setBackgroundColor(Color.TRANSPARENT)代码>
但这没什么区别。那么,我该怎么做呢
这是我的布局图,请看一下
<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>
您可以通过编程实现它,如下所示
webView.getSettings();
webView.setBackgroundColor(Color.TRANSPARENT);
我认为你也应该选择图层类型
mWebView.setLayerType(WebView.LAYER\u TYPE\u软件,空)
祝你好运:)你可以用java试试这个
webView.setBackgroundColor(Color.TRANSPARENT);
webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
试试这个
WebView synopsis;
synopsis=(WebView)findViewById(R.id.synopsis);
synopsis.getSettings();
synopsis.setBackgroundColor(Color.TRANSPARENT);
将此代码放在xml中:
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" />
好的,在四处搜索之后,我发现,要在加载后更改网页的颜色,需要CSS自定义,webview中的任何设置都不能使网页透明(至少在我的情况下)。谢谢!但我已经就这个问题写过大纲了。挫折背景色(Color.TRANSPARENT);不工作。什么webView.setBackgroundColor(Color.TRANSPARENT);这样做,它一开始会使webview透明,在活动开始时,我可以看到我的主题颜色,但在网页开始加载后,它会消失,网页的颜色会出现。不,它不起作用。在加载网页之前,它保持透明,但一旦加载,它就会获得网页的颜色至少要先自己测试一下,因为WebView根本不允许背景。
yourWebView.setBackgroundColor(Color.TRANSPARENT);