在android中设置背景颜色时动画[重复]
Posted
技术标签:
【中文标题】在android中设置背景颜色时动画[重复]【英文标题】:Animate while setBackgroundColor in android [duplicate] 【发布时间】:2018-09-14 23:23:28 【问题描述】:我正在开发自定义步进器。 一切正常。
我现在要做的是在填充当前步骤时为步进器设置动画。
这张图片显示了我的想法:
这是我在设置线条、标题和图标 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;
位置是当前步骤。
这是我的用户界面:
正如我所说,我想在每次从一个步骤移动到另一个步骤时为线条设置动画。
谢谢你:)
【问题讨论】:
【参考方案1】:好吧,你可以让那条线成为progressBar并动画设置它的进度。
动画是这样完成的: Animate ProgressBar update in android
或者您可以为视图背景设置动画,只需使用带有动画的可绘制对象,请查看此处: Animate change of view background color on Android
【讨论】:
以上是关于在android中设置背景颜色时动画[重复]的主要内容,如果未能解决你的问题,请参考以下文章
Android Studio:如果您设置项目的背景颜色,ListView OnClick 动画将不起作用