2013-05-02 91 views
1

我有一個ProgressBar,當加載WebView時顯示。我希望ProgressBar顯示爲小尺寸,而背景爲黑色。然後,我可以在WebView加載時關閉進度條。WebView在進度條加載時顯示爲白色

我遇到的問題是WebView在加載時是白色的。有什麼辦法讓它變黑嗎?如果我將WebView的背景顏色設置爲黑色,短暫一秒,它仍然是白色的,並且使加載非常難看。

活動的佈局是:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

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

    <ProgressBar 
     android:id="@+id/ProgressBar" 
     style="?android:attr/progressBarStyle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:visibility="gone" /> 

</RelativeLayout> 

或者,我應該使用某種形式的圖像看起來類似於Android的進度條?

回答

2

以下內容添加到您的XML:

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

而在代碼執行此操作:

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
    Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    // Inflate the layout for this fragment 
    View view = inflater.inflate(R.layout.feed_fragment, container, false); 

    WebView webView = (WebView) view.findViewById(
      R.id.webview); 
    webView.setBackgroundColor(0); 

    return view; 
} 
+1

都能跟得上添加此。那不起作用 – rajath 2013-05-02 10:02:42

+0

在代碼中設置它爲我工作。我已經更新了答案,你可以試試嗎? – 2013-05-02 11:26:12

+0

如果我嘗試這樣做,白屏出現的時間較短,儘管仍然存在 – rajath 2013-05-02 11:33:22

0

在你的RelativeLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#000000"> 
+0

我也試過,但不起作用。 – rajath 2013-05-02 11:33:49

+2

您可以做一件事,首先將webView的可見性設置爲不可見,直到進度條加載,此時進度條被取消setVisibility爲可見 – Saad 2013-05-02 13:04:00