2017-06-01 45 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