为了账号安全,请及时绑定邮箱和手机立即绑定

获取背景按钮并将此颜色应用于另一种颜色

获取背景按钮并将此颜色应用于另一种颜色

萧十郎 2023-06-21 14:42:24
我在 android studio 上有一个项目,我需要获取按钮的背景颜色以将颜色应用到另一个按钮。我试过这个:ColorDrawable BgColor = (ColorDrawable) btn_next.getBackground(); btn_filRouge.setBackgroundColor(BgColor);我想将 ColorDrawable 转换为 int。或者直接将颜色获取到 int 中。
查看完整描述

1 回答

?
月关宝盒

TA贡献1772条经验 获得超5个赞

我想将 ColorDrawable 转换为 int。或者直接将颜色获取到 int

您无法将 ColorDrawable 转换为 int,但您可以按照第二个解决方案,答案就在您的问题中,您可以使用getColor()

ColorDrawable bgColor = (ColorDrawable) btn_next.getBackground();
int color = bgColor.getColor();
查看完整回答
反对 回复 2023-06-21
  • 1 回答
  • 0 关注
  • 79 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信