Android - 设置ProgressDialog的大小

问题描述:

当我的WebView加载时,我需要显示一个ProgressDialog,以便用户无法看到在后台加载的页面。我只能让我的对话框显示为一个小框,我希望对话框填充操作栏下面的所有空间。Android - 设置ProgressDialog的大小

我该如何做到这一点?我已经使用方法progressDialog.setProgressStyle()但没有任何运气。

如果还有其他更好的方法来实现这一点,请让我知道。我的最终目标是让应用的行为像Facebook(原生)应用,其中“加载”指示符在页面加载完成之前可见。

+0

ProgressDialog.setProgressStyle(android.R.attr.progressBarStyleSmall);尝试使用此参数。 – Gridtestmail

+0

不幸的是,添加这个不会改变任何东西 – SteveEdson

我自己解决了这个问题。我使用了不同的方法来达到同样的效果。我不知道它是否是最好的做法,但我的WebView布局现在看起来是这样的:

<LinearLayout 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 progress --> 

    <LinearLayout 
     android:id="@+id/webProgress" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_gravity="center" 
     android:gravity="center_horizontal" 
     android:orientation="vertical" 
     android:visibility="gone" > 

     <ProgressBar 
      style="?android:attr/progressBarStyleLarge" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="8dp" /> 

     <TextView 
      android:id="@+id/login_status_message" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="16dp" 
      android:text="Loading" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 
    </LinearLayout> 

    <WebView 
     android:id="@+id/webView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:visibility="visible" /> 

</LinearLayout> 

而显示和隐藏我使用进度:

View webProgress = findViewById(R.id.webProgress); 

...

public void showWVProgress() { 
    webProgress.setVisibility(View.VISIBLE); 
    isWVProgressShowing = true;  
} 

public void hideWVProgress() { 
    webProgress.setVisibility(View.GONE); 
    isWVProgressShowing = false; 
}