android - 显示加载指示器时禁用所有触摸

标签 android

我有一个简单的主布局,然后我添加了一个 fragment 布局,该布局仅显示在该主布局顶部加载的指示器。问题是我仍然可以按下加载指示器后面的按钮。

有没有办法禁用触摸以使其不会传递到背面?我不想一个一个禁用主屏幕上的每个按钮。

最佳答案

您可以在包含 ProgressBar 的布局中将“clickable”属性设置为“true”:

<FrameLayout 
    android:id="@+id/progressBarContainer"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:clickable="true" >

    <ProgressBar
        android:id="@+id/progressBar" 
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_gravity="center" />

</FrameLayout>

然后,当 ProgressBar 可见时,它的容器(尽管它是不可见的,但它会填满整个屏幕)将拦截任何点击事件,这样它们就不会在 ProgressBar 显示时落入底层布局。

要使用它,请在您想要显示 ProgressBar 时执行此操作:

findViewById(R.id.progressBarContainer).setVisibility(View.VISIBLE);

然后在完成后执行此操作:

findViewById(R.id.progressBarContainer).setVisibility(View.INVISIBLE);

例如,如果您在 AsyncTask 中使用它,您可以使其在 onPreExecute() 中可见,然后在 onPostExecute() 中使其不可见。

关于android - 显示加载指示器时禁用所有触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24541411/

相关文章:

android - 我们可以删除/清除先前设置的 TAG 到 View 吗?

android - Unity 如何调用 Activity 的 onNewIntent()

android - "Unfortunately, App name has stopped"简单应用

android - 如何实现从受信任的 Web Activity 进行 Play 商店购买?

android - 应用内计费 - 快速设备定位 - 导致崩溃(IllegalStateException)

android - 约束布局在应用程序运行时不显示来自 ImageView 的图像

android - Mvvmcross:无法创建首选项 Activity

android - 在 Cocos Creator cocos2d-x 中减小游戏大小

Android 应用程序在第二次启动时卡住

android - Phonegap + Jquery Mobile Android App 表单提交