Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the background of webview in android

Tags:

android

I am developing an android game application,I have implemented all the screens.Now i want to change the webview background color,Can anybody guide me.Here is my xml file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background">

<WebView  
    android:id="@+id/webbrowser"  
    android:layout_width="fill_parent" 
    android:layout_height="345px"
    android:layout_marginTop="46px"/>

 <Button
    android:id="@+id/Btn"
    android:background="@drawable/back_btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="109px"
    android:layout_marginTop="37px">
 </Button>
</LinearLayout>

And My Java file is package com.tli.roadtripbingo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;

public class WebView1 extends Activity {
    private Button Back;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         requestWindowFeature(Window.FEATURE_NO_TITLE);
         setContentView(R.layout.webview);
         Back = (Button)findViewById(R.id.back);

        WebView webView = (WebView) findViewById(R.id.webbrowser);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("http://www.vikingredning.no/skilt.aspx");
        webView.setWebViewClient(new HelloWebViewClient());
        }
    class HelloWebViewClient extends WebViewClient 
    {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) 
        {
            view.loadUrl(url);
            return true;
        }
    };
}

Thanks in advance Regards Tushar

like image 231
User Avatar asked Feb 10 '11 05:02

User


People also ask

How do I change the background color in react native WebView?

No, you cannot change the background color of a webview, but you can use another view with your background color cover on your web view.

Is Android WebView deprecated?

The Android system webview custom cache file has been deprecated and removed in Android 13. New apps and any app updates will now use the operating system default cache location.


2 Answers

You can find answer here Change Background color and font color

WebView myWebView = (WebView) findViewById(R.id.myWebView);
myWebView.setBackgroundColor(Color.parseColor("#123456"));
like image 127
AlexKorovyansky Avatar answered Sep 28 '22 23:09

AlexKorovyansky


You can make the WebView transparent like this:

WebView webView = (WebView) findViewById(R.id.webView);
webView.setBackgroundColor(Color.TRANSPARENT);
like image 34
Ameen Maheen Avatar answered Sep 28 '22 21:09

Ameen Maheen