Change background of ProgressDialog

前端 未结 2 742
悲哀的现实
悲哀的现实 2020-11-28 09:30

I am trying to change the background of a ProgressDialog. I searched the net and found various suggestions (like How to remove border from Dialog?), but I am un

2条回答
  •  抹茶落季
    2020-11-28 09:58

    You can try my gist. It basicly sets a color filter on drawable.

    import android.content.Context;
    import android.graphics.Color;
    import android.util.AttributeSet;
    import android.widget.ProgressBar;
    
    public class ColoredProgressBar extends ProgressBar {
       public ColoredProgressBar(Context context) {
          super(context);
          if (!isInEditMode())
             init();
       }
    
       public ColoredProgressBar(Context context, AttributeSet attrs) {
          super(context, attrs);
          if (!isInEditMode())
             init();
       }
    
       public ColoredProgressBar(Context context, AttributeSet attrs, int defStyle) {
          super(context, attrs, defStyle);
          if (!isInEditMode())
             init();
       }
    
       /**
        * Changes color.
        */
       private void init() {
          getIndeterminateDrawable().setColorFilter(Color.BLUE, android.graphics.PorterDuff.Mode.MULTIPLY);
       }
    }
    

提交回复
热议问题