Android WebView background color

前端 未结 8 1842
情话喂你
情话喂你 2020-12-29 00:47

I am adding to my layout a WebView to display justified text. I want to set the background of the WebView to be transparent to appear like a textView. Here\'s what I did:

相关标签:
8条回答
  • 2020-12-29 01:27

    You must put this in the XML code :

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

    for your web view like this for example :

    <WebView
        android:id="@+id/MyWebView"
        android:layout_width="fill_parent"
        android:layout_height="62dp"
        android:background="@android:color/transparent"
        android:scrollbars="none" />
    

    and after this you must go to Java code and write this before loadUrl :

    yourWebView.setBackgroundColor(Color.TRANSPARENT);
    
    0 讨论(0)
  • 2020-12-29 01:28

    You can find a few tips here: http://code.google.com/p/android/issues/detail?id=14749 and also here: Android WebView style background-color:transparent ignored on android 2.2

    0 讨论(0)
  • 2020-12-29 01:30

    try below code hope use full for you:-

    webview.setBackgroundColor(Color.parseColor("#919191"));
    

    grey code : #919191

    0 讨论(0)
  • 2020-12-29 01:32

    Your html code sets everything to white

    Replace:

    
        String textTitleStyling = "<head><style>* {margin:0;padding:0;font-size:20; " + 
        "text-align:justify; color:#FFFFFF;}</style></head>"; 
    
        String titleWithStyle = textTitleStyling + "<body><h1>" + movie.synopsis +
        "</h1></body>";
    
        synopsis.loadData(textTitleStyling + movie.synopsis, "text/html", "utf-8"); 
        synopsis = (WebView) findViewById(R.id.synopsis); 
        synopsis.getSettings(); 
        synopsis.setBackgroundColor(0);
    
    

    With:

    This excludes color from header style and applies the rest of the style only to body element

    
        String textTitleStyling = "<head><style>body{margin:0;padding:0;font-size:20; " + 
        "text-align:justify;}</style></head>"; 
    
        String titleWithStyle = textTitleStyling + "<body><h1>" + movie.synopsis +
        "</h1></body>";
    
        synopsis.loadData(titleWithStyle, "text/html", "utf-8"); 
        synopsis = (WebView) findViewById(R.id.synopsis); 
        synopsis.getSettings(); 
        synopsis.setBackgroundColor(0);
    
    

    EDIT: fixed html

    0 讨论(0)
  • 2020-12-29 01:34

    You can also do it -

    webview.setBackgroundColor(getContext().getResources().getColor(android.R.color.transparent));
    

    Here android.R.color.transparent is transparent color which is belongs to android fragmework.

    0 讨论(0)
  • 2020-12-29 01:39

    Try using synopsis.getSettings();

    WebView synopsis;
    synopsis=(WebView)findViewById(R.id.synopsis);
    synopsis.setBackgroundColor(Color.TRANSPARENT);
    
    0 讨论(0)
提交回复
热议问题