【问题标题】:Change circle icon in Dialog更改对话框中的圆圈图标
【发布时间】:2016-02-23 08:34:19
【问题描述】:

我有一个包含此代码的对话框:

 progressDialog = new ProgressDialog(this);

    //-------------------------------------

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        progressDialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.custom_progress_background, getTheme()));
    }
    else{
        progressDialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.custom_progress_background));
    }

    //-------------------------------------
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setMessage(getString(R.string.MSG_SEARCH_DOING));
    progressDialog.setCancelable(false);
    progressDialog.setCanceledOnTouchOutside(false);
    progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel_msg), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            isStop = true;
            isCancel = true;
            showWaitingDialog();
        }
    });
    progressDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {

        }
    });
    progressDialog.show();

并有输出:

但我想要这样的微调器:

任何人都可以在不使用第三个库的情况下帮助我做到这一点?

【问题讨论】:

    标签: java android android-alertdialog progressdialog


    【解决方案1】:

    使用这行代码更改进度图标 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { progressDialog.setIndeterminateDrawable(getResources.getDrawable(R.drawable.custom_progress_drawable,getTheme())); }else{ progressDialog.setIndeterminateDrawable(getResources.getDrawable(R.drawable.custom_progress_drawable)); } 你需要至少 4 张图片来制作这个 custom_progress_drawable.xml,它可以创建如下:

    <animation-list>
    <item android:drawable="@drawable/image1" android:duration="100" />
    <item android:drawable="@drawable/image2" android:duration="100" />
    <item android:drawable="@drawable/image3" android:duration="100" />
    <item android:drawable="@drawable/image4" android:duration="100" /></animation-list>
    

    现在将此可绘制对象设置为进度对话框中的中间可绘制对象

    【讨论】:

    • 但是我的 min sdk 只能是 9。这行代码要求 min sdk 是 21
    • 非常感谢,它工作。但为什么它不旋转?我怎样才能让这个圆圈旋转?
    • 你能指导我如何让圆圈旋转吗?您的线路代码可以更改圆圈的图标,但不能旋转。
    • 请粘贴整个代码以显示进度对话框。
    • 代码看起来没问题,您确定要在可绘制的 xml 中添加旋转标签吗??
    【解决方案2】:

    在res目录下新建一个xml文件夹,将progressbar.xml文件放入其中。

     <?xml version="1.0" encoding="utf-8"?>
     <rotate xmlns:android="http://schemas.android.com/apk/res/android"
        android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0"
        android:toDegrees="360">
        <shape android:shape="ring" android:innerRadiusRatio="3"
            android:thicknessRatio="8" android:useLevel="false">
    
            <size android:width="72dip" android:height="72dip" />
            <gradient android:type="sweep" android:useLevel="false"
                android:startColor="#448a29" 
                android:endColor="#447829"
                android:angle="0"
                 />
        </shape>
    </rotate> 
    

    根据您的选择设置 startColor 和 endColor 。

    现在在 ProgressBar 的背景中设置 progress.xml

    这样

    <ProgressBar
     android:id="@+id/ProgressBar" 
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:background ="@xml/progressbar">
    

    你使用了这个示例和库https://github.com/afollestad/material-dialogs

    【讨论】:

    • 我可以更改进度对话框的图标吗?
    • 是的,您可以更改图标和progressDialog圆圈颜色。
    • 没有图书馆怎么办?可以详细指导一下吗?
    • 你使用了这个样本和库https://github.com/afollestad/material-dialogs
    • 我看不到圆圈的更改图标在哪里。 :(
    【解决方案3】:

    你可以像这样自定义你的进度对话,这正是你要找的

    ACProgressFlower dialog = new ACProgressFlower.Builder(this)
                            .direction(ACProgressConstant.DIRECT_CLOCKWISE)
                            .themeColor(Color.WHITE)
                            .text("Title is here)
                            .fadeColor(Color.DKGRAY).build();
    dialog.show();
    

    更多信息请参见this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-08-15
      • 1970-01-01
      • 2023-03-18
      • 2019-02-12
      • 2017-07-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多