我在 android studio 上有一個(gè)項(xiàng)目,我需要獲取按鈕的背景顏色以將顏色應(yīng)用到另一個(gè)按鈕。我試過(guò)這個(gè):ColorDrawable BgColor = (ColorDrawable) btn_next.getBackground();
btn_filRouge.setBackgroundColor(BgColor);我想將 ColorDrawable 轉(zhuǎn)換為 int?;蛘咧苯訉㈩伾@取到 int 中。
1 回答

月關(guān)寶盒
TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超5個(gè)贊
我想將 ColorDrawable 轉(zhuǎn)換為 int。或者直接將顏色獲取到 int中。
您無(wú)法將 ColorDrawable 轉(zhuǎn)換為 int,但您可以按照第二個(gè)解決方案,答案就在您的問(wèn)題中,您可以使用getColor()
:
ColorDrawable?bgColor?=?(ColorDrawable)?btn_next.getBackground(); int?color?=?bgColor.getColor();
添加回答
舉報(bào)
0/150
提交
取消