Luca Panteghini
Luca Panteghini

Reputation: 3086

WebView setBackgroundColor not work in Android

I've try all suggestion that I've found but no one works for me. This code not affect background color on webview in 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);

How I can make works this simply function?

Upvotes: 2

Views: 4724

Answers (1)

Harshad Pansuriya
Harshad Pansuriya

Reputation: 20930

just change this

myWebView.setBackgroundColor(0);

to this

myWebView.setBackgroundColor(Color.BLUE);

because it working fine.

see my full code..

xml code :

<?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 code.

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

output :

enter image description here

Upvotes: 3

Related Questions