2013-05-02 89 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