AnswerBun.com

i converted website into app using webview. but website background is not appearing in my app

Stack Overflow Asked by Neha Bhosale on January 13, 2021

<WebView
    android:id="@+id/webView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:scrollbars="none"
    />
</androidx.constraintlayout.widget.ConstraintLayout>
public class MainActivity extends AppCompatActivity {
    private WebView mywebview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mywebview = (WebView) findViewById(R.id.webView);
        mywebview.setWebViewClient(new WebViewClient());
        mywebview.setBackgroundResource(R.drawable.wordpress);
        mywebview.setBackgroundColor(Color.TRANSPARENT);
        WebSettings webSettings = mywebview.getSettings();
        webSettings.setJavaScriptEnabled(true);
        mywebview.loadUrl("https://www.indianfests.com/");
    }
    @Override
    public void onBackPressed() {
        if (mywebview.canGoBack()) {
            mywebview.goBack();
        } else {
            super.onBackPressed();
        }
    }
}

2 Answers

If you mean the background image with the elephant statue that we see on https://www.indianfests.com/ is not loading: this is probably because Android requires all requests to use HTTPS by default from target API level 28 onwards.

The background image, however, is specified as plain HTTP: http://www.indianfests.com/wp-content/uploads/2020/08/wordpress.jpg. The server immediately redirects it to HTTPS, but because the HTTP request is blocked, the WebView cannot know that (and even if it did, it would be insecure to use it anyway). You can also see this in a regular web browser, which should show some kind of warning text or icon in the address bar.

So the best way to fix this is to simply change the website to use HTTPS throughout.

If you absolutely, positively cannot do that, you can use <application android:usesClearTextTraffic="true"> in your manifest (documentation). But for the security of your users, please consider this a last resort.

Answered by Thomas on January 13, 2021

Remove following...

mywebview.setBackgroundResource(R.drawable.wordpress);
mywebview.setBackgroundColor(Color.TRANSPARENT);

from XMl:

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

Answered by chand mohd on January 13, 2021

Add your own answers!

Related Questions

SQL Query [Count the result of a query]

0  Asked on February 3, 2021 by abdelhalim

     

function stops when fetch() fails

2  Asked on February 2, 2021 by uncannyorange

 

merging lists of dataframes in R effectively

1  Asked on February 2, 2021 by user5813583

   

The Math behind a tesorflow.tensordot()

0  Asked on February 1, 2021 by harsh-dhamecha

     

How to check if a word contains one letter from another string

3  Asked on February 1, 2021 by umar-zahid

   

How to use citeproc-java on Android

1  Asked on February 1, 2021 by hector

     

Laravel whereHas Filter sub relation

1  Asked on February 1, 2021 by bryant-tang

 

How to check if list contains dict element with same key

1  Asked on February 1, 2021 by radosaw-hryniewicki

     

react-navigation nested drawer items

1  Asked on February 1, 2021 by caner-akmak

     

Add a header to an outgoing request by a filter in WebFlux

1  Asked on February 1, 2021 by jae-young-lee

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir