【问题标题】:Material Design Progress Dialog with transparent background具有透明背景的材料设计进度对话框
【发布时间】:2015-07-17 09:05:48
【问题描述】:

我想在我的应用中放置一个符合材料的不确定进度对话框。我找到了两种方法来实现它:

1- 使用材料对话框:https://github.com/afollestad/material-dialogs

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

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

我想要的只是圆形进度条,没有周围的浅灰色视图,也没有任何文字。许多应用程序向我们证明,用户知道,当事情发生时,他只需要等待:不需要写信。我的意思很像this,但很重要。

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

谢谢

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

【问题讨论】:

    标签: android progressdialog material-design android-progressbar


    【解决方案1】:

    您可以使用此代码,在设备 >= 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>
    

    【讨论】:

    • elemento_progress_splash 中有什么??
    【解决方案2】:

    总结我们与作者的努力:

    主要目标是为具有对话框本身透明背景的“材质进度轮”类型的进度指示器获得对话框外观效果(特别是背景变暗)。

    我们是如何做到的(一种可能的方式):

    1. This library用作素材进度轮。

    2. 创建一个单独的布局文件(例如,progress_wheel.xml),其中包含进度轮布局&lt;com.pnikosis.materialishprogress.ProgressWheel&gt;...。如果您发现轮子的尺寸没有根据您的布局设置更改,请使用 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;
            }
        }
    }
    

    【讨论】:

    • 谢谢,但是...“Material-ish Progress”在我看来,这似乎是一个进度轮或进度条,而不是对话框。如何将其作为具有透明背景的对话框?这同样适用于其他人......
    • @MarKco 在这种情况下,对话是什么意思? Mb 我没有正确理解你的想法,但我在你的第二张照片上看到的对我来说很像一个进度轮。
    • 可能我不够清楚,对不起。我想得到类似i.stack.imgur.com/h6viz.gif 的东西,如stackoverflow.com/questions/5442183/… 中所述,但是那个人想把纺车放在布局中,我想让它像一个所有背景变暗的覆盖对话框(作为我放的第一张图片)但没有背景和文字(就像第二张一样)。想象一下,没有文字、水平线和背景:tinyurl.com/jwc3ylm - 我希望我现在更清楚了。
    • @MarKco 好的。如果您仅使用此进度轮创建单独的布局文件会怎样。然后做这样的事情:Dialog progressDialog = new Dialog(this); progressDialog.setContentView(R.layout.progressWheel); progressDialog.show();。这样,您应该将进度轮放在屏幕中间,很可能它会在透明背景上,而且您将免费获得调光效果。不过,还需要进行一些实验。
    • 您好,我尝试使用Dialog progressDialog = new Dialog(context); progressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); progressDialog.setContentView(R.layout.material_progress_dialog); progressDialog.show();,但只实现了这一点(在尝试使 bkg 透明并删除标题栏之后):i58.tinypic.com/r8imo7.png 我真的很想删除那些空白,但我不知道它是在哪里定义的:-/我已经尝试过对其进行样式设置,但也没有用。
    猜你喜欢
    • 2015-04-16
    • 2020-07-16
    • 2012-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-09
    • 2017-02-20
    相关资源
    最近更新 更多