Android progressbar_horizontal简单封装

只有干货
效果图
1、布局



    

    

        

            

            
        

        

            

            
        

        

            

            
        

        

            

            
        
    




2、相关布局
draw_dot_10




    

    


circle_dotted_line




    

    

    


进度条颜色设置




    
    
        
            
            
        
    
    
    
        
            
                
                
            
        
    

自定义view-ProgressView

/**
 * Created by hx
 * Time 2018/11/16/016.
 */

public class ProgressView extends RelativeLayout {
    public static final int STEP_ONE = 1;
    public static final int STEP_TWO = 2;
    public static final int STEP_THREE = 3;
    public static final int STEP_FOUR = 4;
    private ProgressBar mBar;
    private TextView tvNum1, tvText1, tvNum2, tvText2, tvNum3, tvText3, tvNum4, tvText4;
    private List numList = new ArrayList<>();
    private List textList = new ArrayList<>();

    public ProgressView(Context context) {
        super(context);
    }

    public ProgressView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // 加载布局
        LayoutInflater.from(context).inflate(R.layout.layout_group_progress, this);
        // 获取控件
        mBar = findViewById(R.id.pb_group_step);
        tvNum1 = findViewById(R.id.tv_step_one_num);
        tvText1 = findViewById(R.id.tv_step_one_text);
        tvNum2 = findViewById(R.id.tv_step_two_num);
        tvText2 = findViewById(R.id.tv_step_two_text);
        tvNum3 = findViewById(R.id.tv_step_three_num);
        tvText3 = findViewById(R.id.tv_step_three_text);
        tvNum4 = findViewById(R.id.tv_step_four_num);
        tvText4 = findViewById(R.id.tv_step_four_text);
        numList.add(tvNum1);
        numList.add(tvNum2);
        numList.add(tvNum3);
        numList.add(tvNum4);
        textList.add(tvText1);
        textList.add(tvText2);
        textList.add(tvText3);
        textList.add(tvText4);
    }

    public void setStep(int mStep) {
        switch (mStep) {
            case STEP_ONE:
                mBar.setProgress(16);
                setTextColor(mStep);
                break;
            case STEP_TWO:
                mBar.setProgress(50);
                setTextColor(mStep);
                break;
            case STEP_THREE:
                mBar.setProgress(82);
                setTextColor(mStep);
                break;
            case STEP_FOUR:
                mBar.setProgress(100);
                setTextColor(mStep);
                break;
        }
    }

    private void setTextColor(int mStep) {
        for (int i = 0; i < 4; i++) {
            if (i < mStep) {
                numList.get(i).setTextColor(getResources().getColor(R.color.white));
                numList.get(i).setBackground(getResources().getDrawable(R.drawable.draw_dot_10));
                textList.get(i).setTextColor(getResources().getColor(R.color.main_color_pink));
            } else {
                numList.get(i).setTextColor(getResources().getColor(R.color.text_color));
                numList.get(i).setBackground(getResources().getDrawable(R.drawable.circle_dotted_line));
                textList.get(i).setTextColor(getResources().getColor(R.color.text_color));
            }

        }
    }
}

引用:

progress = (ProgressView) findViewById(R.id.progress);
progress.setStep(ProgressView.STEP_ONE);

以上系本人记录

你可能感兴趣的:(Android progressbar_horizontal简单封装)