2

我尝试了所有我发现但没有人适用于我的建议。 这个代码不影响背景颜色的WebView在安卓WebView setBackgroundColor在Android中不起作用

myWebView = (WebView) findViewById(R.id.webview1); 

myWebView.setWebChromeClient(new WebChromeClient()); 
myWebView.getSettings().setJavaScriptEnabled(true); 
myWebView.getSettings().setLoadWithOverviewMode(true); 
myWebView.getSettings().setUseWideViewPort(true); 
myWebView.getSettings(); 
myWebView.setBackgroundColor(0); 

我如何让作品这只是功能?

+0

我试过黑色,白色和透明。现在我正在尝试透明。 –

+0

请参阅下面的答案。 – Ironman

+0

不适用于我:-( –

回答

1

,因为它工作正常,只是改变这种

myWebView.setBackgroundColor(0); 

这个

myWebView.setBackgroundColor(Color.BLUE); 

看到我的全部代码..

XML代码:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="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:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.example.softeng.abcd.Main2Activity" 
    tools:showIn="@layout/activity_main2" 
    > 

    <WebView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/webview"></WebView> 

</RelativeLayout> 

Java代码。

WebView webview = (WebView)findViewById(R.id.webview); 
     webview.getSettings().setJavaScriptEnabled(true); 
     webview.getSettings().setLoadWithOverviewMode(true); 
     webview.getSettings().setUseWideViewPort(true); 
     webview.getSettings(); 
     webview.setBackgroundColor(Color.BLUE); 

输出:

enter image description here

+0

@Luca Panteghini查看我的更新答案,如果不行,那么尝试“清理”该项目。 – Ironman

+0

蓝色,黄色或绿色的作品,但白色或透明的不工作奇怪的事情!!!在相同的情况下显示灰色和不是白色 –

+0

@LucaPanteghini没有所有的工作在'白色'的情况下,你已经设置'父'背景的其他'颜色'和'transaparent'的情况下,它也可以工作,但人类无法看到'透明'颜色,所以它不能显示我们,否则它也可以。 – Ironman

相关问题