我正在研究自定义步进器。 一切都很好。
我现在要做的是在填充当前步骤时为步进器设置动画。
此图片显示了我的想法:
这是我设置线条,标题和图标src的颜色时的代码:
private void DrawStepper(int position) {
switch (position) {
case 0:
imgStepShipper.setImageResource(R.drawable.ic_current_step);
txtStepShipper.setTextColor(getResources().getColor(R.color.colorPrimary));
line.setBackgroundColor(getResources().getColor(R.color.colorDarkWhite));
imgStepConsignee.setImageResource(R.drawable.ic_unselected_step);
txtStepConsignee.setTextColor(getResources().getColor(R.color.colorDarkSuperWhite));
line2.setBackgroundColor(getResources().getColor(R.color.colorDarkWhite));
imgStepShipment.setImageResource(R.drawable.ic_unselected_step);
txtStepShipment.setTextColor(getResources().getColor(R.color.colorDarkSuperWhite));
line3.setBackgroundColor(getResources().getColor(R.color.colorDarkWhite));
imgStepCharges.setImageResource(R.drawable.ic_unselected_step);
txtStepCharges.setTextColor(getResources().getColor(R.color.colorDarkSuperWhite));
break;
case 1:
imgStepShipper.setImageResource(R.drawable.ic_done_step);
txtStepShipper.setTextColor(getResources().getColor(R.color.colorPrimary));
line.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
imgStepConsignee.setImageResource(R.drawable.ic_current_step);
txtStepConsignee.setTextColor(getResources().getColor(R.color.colorPrimary));
line2.setBackgroundColor(getResources().getColor(R.color.colorDarkWhite));
imgStepShipment.setImageResource(R.drawable.ic_unselected_step);
txtStepShipment.setTextColor(getResources().getColor(R.color.colorDarkSuperWhite));
line3.setBackgroundColor(getResources().getColor(R.color.colorDarkWhite));
imgStepCharges.setImageResource(R.drawable.ic_unselected_step);
txtStepCharges.setTextColor(getResources().getColor(R.color.colorDarkSuperWhite));
break;
case 2:
imgStepShipper.setImageResource(R.drawable.ic_done_step);
txtStepShipper.setTextColor(getResources().getColor(R.color.colorPrimary));
line.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
imgStepConsignee.setImageResource(R.drawable.ic_done_step);
txtStepConsignee.setTextColor(getResources().getColor(R.color.colorPrimary));
line2.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
imgStepShipment.setImageResource(R.drawable.ic_current_step);
txtStepShipment.setTextColor(getResources().getColor(R.color.colorPrimary));
line3.setBackgroundColor(getResources().getColor(R.color.colorDarkWhite));
imgStepCharges.setImageResource(R.drawable.ic_unselected_step);
txtStepCharges.setTextColor(getResources().getColor(R.color.colorDarkSuperWhite));
break;
case 3:
imgStepShipper.setImageResource(R.drawable.ic_done_step);
txtStepShipper.setTextColor(getResources().getColor(R.color.colorPrimary));
line.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
imgStepConsignee.setImageResource(R.drawable.ic_done_step);
txtStepConsignee.setTextColor(getResources().getColor(R.color.colorPrimary));
line2.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
imgStepShipment.setImageResource(R.drawable.ic_done_step);
txtStepShipment.setTextColor(getResources().getColor(R.color.colorPrimary));
line3.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
imgStepCharges.setImageResource(R.drawable.ic_current_step);
txtStepCharges.setTextColor(getResources().getColor(R.color.colorPrimary));
break;
}
}
位置是当前步骤。
这是我的用户界面:
正如我所说,我希望每次从一个步骤移动到另一个时为该线设置动画。
谢谢:)
答案 0 :(得分:1)
好吧,你可以将该行设置为progressBar并设置动画来设置其进度。
这是动画的完成方式: Animate ProgressBar update in Android
或者您可以为视图背景设置动画,只需使用带动画的drawable,请点击此处: Animate change of view background color on Android