Material 具有透明背景的设计进度对话框

Material Design Progress Dialog with transparent background

我想在我的应用程序中放置一个不确定的进度对话框 material-compliant。我找到了两种实现方式:

1- 使用 material-dialogs:https://github.com/afollestad/material-dialogs

2- 使用 material-design-library 的 build-in 对话框:https://github.com/navasmdc/MaterialDesignLibrary#dialog

使用这些解决方案中的任何一个,我得到的结果非常类似于 this:一个带有进度条的对话框。

我想要的只是圆形进度条,没有周围的 light-grey 视图,也没有任何文本。许多应用程序向我们证明,用户知道当有东西在旋转时他只需要等待:没有必要用字母写出来。我的意思几乎是 this,但是 material.

我不认为这是一个奇怪的问题(或者是吗?),但我无法在网上找到任何好的答案。你们有人知道如何实现吗?

谢谢

[编辑] 我必须说,在 material-dialogs 库的 gitHub 问题中,这似乎被讨论了,但开发人员很快就关闭了它,说这意味着不遵循指南: https://github.com/afollestad/material-dialogs/issues/277

总结我们与作者的共同努力:

主要 objective 是为具有对话框本身透明背景的类型 "material progress wheel" 的进度指示器获得对话框外观效果(特别是背景变暗)。

我们是如何处理的(可能的方法之一):

  1. This library用作material进度轮。

  2. 创建了一个单独的布局文件(例如,progress_wheel.xml),其中包含进度轮布局 <com.pnikosis.materialishprogress.ProgressWheel>...。如果您发现轮子的尺寸没有根据您的布局设置更改,请用 FrameLayoutwrap_content 尺寸将其包裹起来。

  3. 使用布局充气器为该布局充气以获得视图,例如dialogView.

  4. 创建对话框:

Dialog progressDialog = new Dialog(context);
progressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
progressDialog.setContentView(dialogView);
progressDialog.show();
  1. dialogView 上调用此函数使对话框背景透明:
public static void clearParentsBackgrounds(View view) {
    while (view != null) {
        final ViewParent parent = view.getParent();
        if (parent instanceof View) {
            view = (View) parent;
            view.setBackgroundResource(android.graphics.Color.TRANSPARENT);
        } else {
            view = null;
        }
    }
}

您可以使用此代码,在 >= 19 (Kitkat) 的设备上工作正常

progress = ProgressDialog.show(Splash.this, null, null, true);
            progress.setContentView(R.layout.elemento_progress_splash);
            progress.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

            progress.show();

元素进度splash.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@null"
    >

    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:backgroundTint="@color/ColorTipografiaAdeudos"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="10dp"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="Comprobando sus datos"
        android:layout_below="@+id/progressBar1"
        android:layout_centerHorizontal="true"
        android:id="@+id/textView6"
        android:textSize="20dp"
        android:textStyle="bold"
        android:textColor="@color/ColorFuente"
        android:layout_gravity="center_horizontal" />


</RelativeLayout>