2017-06-01 44 views
1

在Android中,我有一個設置菜單的屏幕,當加載屏幕時我使用ProgressDialog顯示消息「Please wait.while screen loads」,直到搜索完成。安卓多任務當ProgressDialog顯示在屏幕上

我想在當前搜索並且屏幕上仍然顯示ProgressDialog時訪問屏幕中的設置菜單。

我試過progressDialog.cancel(),但是這隱藏了進度對話框消息,然後讓我進入菜單。但是我想在訪問菜單時顯示對話框消息。用戶訪問設置菜單時是否可以顯示進度對話框消息?

+2

這是一種矛盾說「請稍候」,同時允許用戶訪問它正在等待。你可能需要更清楚你想要達到的目標。關於我能想到的最接近的事情,你想要做的是使用通知,而不是進度對話框 – codeMagic

+0

我想顯示進度對話框消息給用戶,直到搜索完成。當 搜索操作仍在進行時,我應該能夠訪問菜單,並且在同一屏幕中也應顯示進度對話框,因爲搜索尚未結束。 –

+1

這種方式不使用ProgressDialog。您可以添加視圖(如TextView)並在搜索時切換可見性。仍然聽起來令我感到困惑 – codeMagic

回答

1

根據您的要求,您可能不應該使用ProgressDialog,因爲它會「鎖定」用戶操作,直到您取消它(或用戶通過按下後退按鈕將其解除)。

另一種解決方案是創建一箇中心ProgressBarTextView視圖,其初始可見性設置爲GONE,那麼一旦你開始加載搜索,您可以在此查看能見度VISIBLE和其他一切改變GONE(除了你希望看到的東西,比如你的菜單)。

雖這麼說,你會得到類似下面的截圖:

Sample loading screen

這樣一來,用戶將能夠與屏幕上的其他組件,如訪問設置菜單交互。

的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> 
+0

我用ProgressBar和TextView,它工作,謝謝你的答案Mauker。 –

+0

非常歡迎!不要忘記標記爲接受:) – Mauker