Android 进度条未显示
The Android Progress bar not showing up
这是我的布局xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/fragment_body"
android:fitsSystemWindows="true">
<include
android:id="@+id/contextToolBar"
layout="@layout/context_toolbar_layout" />
<android.support.v7.widget.RecyclerView
android:id="@+id/list1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/contextToolBar"
android:scrollbarSize="5dp"
android:scrollbarThumbVertical="@color/scrollbarColor"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<ProgressBar
android:id="@+id/delete_progress"
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone" />
它在回收站视图中显示图像网格。
我可以 select 一堆图像并且可以选择删除它们。
以下是删除逻辑:
public void deleteSelectedFiles(final Context context, final List<MediaModel> selectionList) {
String confirmationMessage = getString(R.string.delete_confirm_message);
new AlertDialog.Builder(context)
.setTitle(getString(R.string.action_delete))
.setMessage(confirmationMessage)
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.yes, (dialog, whichButton) -> {
View progressBar = getActivity().findViewById(R.id.delete_progress);
dialog.cancel();
progressBar.setVisibility(View.VISIBLE);
deleteFileList(selectionList, this.getActivity());
progressBar.setVisibility(View.GONE);
})
.setNegativeButton(android.R.string.no, null).show();
}
我希望进度条在删除操作进行时显示在前台。但它只是没有出现。任何帮助将不胜感激。
所以我之前也遇到过这个问题。就我而言,这是因为我为整个应用程序使用了 Material 设计主题,所以我不得不使用特定的方向,它解决了我的问题。你可以试试
<ProgressBar
android:id="@+id/progressBarReady"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="3dp"
android:indeterminate="true"
android:visibility="visible"/>
我遇到了类似的问题。在我的例子中,我使用 ProgressBar 作为 CoordinatorLayout 内的加载指示器。
在 Activity/Fragment - 在不同的点 - 基于可用的数据 - 即使用游标或来自网络,我需要调用
mViewA.setVisibility(View.GONE)
或 mViewB.setVisibility(View.VISIBLE)
。
当我为我的视图(包括 ProgressBar 视图)正确设置这些时,它变得可见。
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
style="?android:attr/progressBarStyle" 是为我修复的。
这是我的布局xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/fragment_body"
android:fitsSystemWindows="true">
<include
android:id="@+id/contextToolBar"
layout="@layout/context_toolbar_layout" />
<android.support.v7.widget.RecyclerView
android:id="@+id/list1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/contextToolBar"
android:scrollbarSize="5dp"
android:scrollbarThumbVertical="@color/scrollbarColor"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<ProgressBar
android:id="@+id/delete_progress"
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone" />
它在回收站视图中显示图像网格。 我可以 select 一堆图像并且可以选择删除它们。 以下是删除逻辑:
public void deleteSelectedFiles(final Context context, final List<MediaModel> selectionList) {
String confirmationMessage = getString(R.string.delete_confirm_message);
new AlertDialog.Builder(context)
.setTitle(getString(R.string.action_delete))
.setMessage(confirmationMessage)
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.yes, (dialog, whichButton) -> {
View progressBar = getActivity().findViewById(R.id.delete_progress);
dialog.cancel();
progressBar.setVisibility(View.VISIBLE);
deleteFileList(selectionList, this.getActivity());
progressBar.setVisibility(View.GONE);
})
.setNegativeButton(android.R.string.no, null).show();
}
我希望进度条在删除操作进行时显示在前台。但它只是没有出现。任何帮助将不胜感激。
所以我之前也遇到过这个问题。就我而言,这是因为我为整个应用程序使用了 Material 设计主题,所以我不得不使用特定的方向,它解决了我的问题。你可以试试
<ProgressBar
android:id="@+id/progressBarReady"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="3dp"
android:indeterminate="true"
android:visibility="visible"/>
我遇到了类似的问题。在我的例子中,我使用 ProgressBar 作为 CoordinatorLayout 内的加载指示器。
在 Activity/Fragment - 在不同的点 - 基于可用的数据 - 即使用游标或来自网络,我需要调用
mViewA.setVisibility(View.GONE)
或 mViewB.setVisibility(View.VISIBLE)
。
当我为我的视图(包括 ProgressBar 视图)正确设置这些时,它变得可见。
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
style="?android:attr/progressBarStyle" 是为我修复的。