我試圖比較一個視圖的背景顏色是否與我創建的顏色資源相同,但未找到任何可用的顏色資源。如何檢索視圖的背景顏色並將其與顏色資源進行比較
我很樂意使用任何方法,無論是轉換爲HEX還是String或Int,只要它有效。這是我目前的方法的一個例子。
我設置視圖的用背景色:
ColorDrawable chosenColorBox = (ColorDrawable) chosenColor.getBackground();
int colorId = chosenColorBox.getColor();
colorId == `-611329`
使用上R.color.tag_pink
Integer.toString
顯示值作爲2130968581
這顯然不能:
chosenColor.setBackgroundColor(getResources().getColor(R.color.tag_pink));
當我使用這種方法檢索它在if
聲明「與檢索值進行比較。
什麼是最佳方式因此我不必對個人價值進行硬編碼,這使我無法調整色彩資源?
!解決方法:colorId = getResources()的getColor(R.color.tag_no_tag_chosen) – papium