简体   繁体   English

如何在android中以编程方式设置默认进度Dialog Spinner颜色

[英]How to set Default progress Dialog Spinner color by programatically in android

I am trying to change default progress dialog spinner color..but I went some tutorial but not usefull 我试图更改默认进度对话框微调颜色..但我去了一些教程,但没有用

    progressDialog.setMessage("Loading...");
    progressDialog.setIndeterminate(true);
    progressDialog.setCancelable(false);
    progressDialog.show();

Try this but i doesn't had text like loading... 尝试这个,但我没有像加载文本...

final ProgressDialog dialog = ProgressDialog.show(MainActivity.this, null, null);
        ProgressBar spinner = new android.widget.ProgressBar(MainActivity.this, null,android.R.attr.progressBarStyle);
        spinner.getIndeterminateDrawable().setColorFilter(Color.parseColor("#53CBF1"), android.graphics.PorterDuff.Mode.SRC_IN);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        dialog.setContentView(spinner);
        dialog.setCancelable(false);
        dialog.show();

change colorAccent in Your main theme` 改变colorAccent在主theme`

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/yourcolor</item>
</style>

For all devices support below 21 you using code by custom layout to progress dialog... 对于21以下的所有设备支持,您可以使用自定义布局的代码来进行对话...

custom_progressdialog.xml custom_progressdialog.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="wrap_content"
    android:background="@android:color/transparent"
    android:id="@+id/rl"
    android:padding="5dp"

>

    <ProgressBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent"
    android:id="@+id/progressbar"
        android:layout_centerVertical="true"

        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Loading..."
        android:layout_toRightOf="@+id/progressbar"
        android:layout_centerVertical="true"
        />

</RelativeLayout>

Code

    progressDialog=new ProgressDialog(demo.this);
    progressDialog.show();
    progressDialog.setContentView(R.layout.custom_progressdialog);
    ProgressBar progressbar=(ProgressBar)progressDialog.findViewById(R.id.progressbar);
    progressbar.getIndeterminateDrawable().setColorFilter(Color.parseColor("#C60000"), android.graphics.PorterDuff.Mode.SRC_IN);
    progressDialog.setCancelable(true);

Step 1: 第1步:

In res Directory, Create 1 XML File and name it progress.xml , This is the code for the file: 在res目录中,创建1个XML文件并将其命名为progress.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="76dip" android:height="76dip" />
        <gradient android:type="sweep" android:useLevel="false"
            android:startColor="#447a29" 
            android:endColor="#447a29"
            android:angle="0"
             />
    </shape>
</rotate> 

Step 2: 第2步:

Modify android:startColor and android:endColor as whatever Color you want. android:startColorandroid:endColor修改为你想要的颜色。

Step 3: 第3步:

set that progress.xml in ProgressBar's backgound . 在ProgressBar的后台设置progress.xml。

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

Answer based on This Page , By Chirag Raval. 答案基于本页 ,由Chirag Raval撰写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM