根據您的要求,您可能不應該使用ProgressDialog
,因爲它會「鎖定」用戶操作,直到您取消它(或用戶通過按下後退按鈕將其解除)。
另一種解決方案是創建一箇中心ProgressBar
和TextView
視圖,其初始可見性設置爲GONE
,那麼一旦你開始加載搜索,您可以在此查看能見度VISIBLE
和其他一切改變GONE
(除了你希望看到的東西,比如你的菜單)。
雖這麼說,你會得到類似下面的截圖:
這樣一來,用戶將能夠與屏幕上的其他組件,如訪問設置菜單交互。
的XML代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="LOADING..."
app:layout_constraintTop_toBottomOf="@+id/progressBar"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
</android.support.constraint.ConstraintLayout>
這是一種矛盾說「請稍候」,同時允許用戶訪問它正在等待。你可能需要更清楚你想要達到的目標。關於我能想到的最接近的事情,你想要做的是使用通知,而不是進度對話框 – codeMagic
我想顯示進度對話框消息給用戶,直到搜索完成。當 搜索操作仍在進行時,我應該能夠訪問菜單,並且在同一屏幕中也應顯示進度對話框,因爲搜索尚未結束。 –
這種方式不使用ProgressDialog。您可以添加視圖(如TextView)並在搜索時切換可見性。仍然聽起來令我感到困惑 – codeMagic