2014-12-05 3 views

답변

2

사용 :

당신이 있다면 당신이 다음 시도 할 수

ColorDrawable buttonColor = (ColorDrawable) button.getBackground(); 

컬러 알고 그리고 있다면 그것은 그리기

Button button = (Button) findViewById(R.id.my_button); 
Drawable buttonBackground = button.getBackground(); 

으로 이것을 쉽게 얻을 Android 3.0 이상에서는 색상의 자원 ID를 가져올 수 있습니다.

int colorId = buttonColor.getColor(); 

그리고 이것을 할당 된 색상 즉,

if (colorID == R.color.green) { 
    log("color is green"); 
} 
+1

감사합니다. 매우 많이 –

+0

배경이 ColorDrawable에 캐스트되어야한다는 것을 알기에는 너무 길었습니다. 고맙습니다. – Alice

관련 문제