我在 android studio 上有一個項目,我需要獲取按鈕的背景顏色以將顏色應用到另一個按鈕。我試過這個:ColorDrawable BgColor = (ColorDrawable) btn_next.getBackground();
btn_filRouge.setBackgroundColor(BgColor);我想將 ColorDrawable 轉換為 int。或者直接將顏色獲取到 int 中。
1 回答

月關寶盒
TA貢獻1772條經驗 獲得超5個贊
我想將 ColorDrawable 轉換為 int?;蛘咧苯訉㈩伾?strong>獲取到 int中。
您無法將 ColorDrawable 轉換為 int,但您可以按照第二個解決方案,答案就在您的問題中,您可以使用getColor()
:
ColorDrawable?bgColor?=?(ColorDrawable)?btn_next.getBackground(); int?color?=?bgColor.getColor();
添加回答
舉報
0/150
提交
取消