android背光调节渐变过程,android 动态修改view的shape颜色(渐变色)

效果图修改前:

b94c796ea7ab

image.png

效果图修改后:

b94c796ea7ab

image.png

orange_shape文件

android:shape="rectangle">

android:startColor="@android:color/holo_red_dark"

android:centerColor="@android:color/holo_green_dark"

android:endColor="@android:color/holo_blue_light"/>

布局layout

android:id="@+id/topView"

android:layout_width="match_parent"

android:layout_height="40dp"

android:background="@drawable/orange_shape" />

activity(这种方案必须有设置shape后才能使用)

int[] colorsTwo = {Color.parseColor("#FFA538"),Color.parseColor("#FFC848"),Color.parseColor("#FFC848"),};

GradientDrawable backView = (GradientDrawable) view.getBackground();

backView.setColors(colorsTwo);

另外一种方案

int[] colors = {0xFFFF9326,0xFFFFC54E};

int[] colors = {Color.parseColor("#ffffff"),Color.parseColor("#ffffff")};

GradientDrawable drawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,colors);

drawable.setCornerRadius(0);

view.setBackground(drawable);

有更好的实现方案,希望小伙伴给与文章参考连接或思路

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值