2017-12-25 12 views
1

보기의 배경색을 16 진수 형식으로 가져 오려고합니다.16 진수보기의 배경색 얻기

예를 들어 int getViewBackgroundColor(View view)을 예외로 간주합니다. 내 예외는 0Xff256e78입니다.

어떻게하면됩니까?

감사합니다.

답변

1
LinearLayout layout = (LinearLayout) findViewById(R.id.lay1); 
ColorDrawable viewColor = (ColorDrawable) layoutgetBackground(); 
int colorId = viewColor.getColor(); 

색상의 정수 유형으로받은 후 지금 u는 헥사이 도움이

String hexColor = String.format("#%06X", (0xFFFFFF & colorId)); 

희망 .. 작동

+0

감사 CONVRT해야하지만, 그것을 얻기 위해, 문자열의 long ->'Long.parseLong (hexColorString, 16)' –

0

다음 코드는보기의 배경색을 가져 와서 색상의 int 표현으로 변환합니다.

ColorDrawable buttonColor = (ColorDrawable) myView.getBackground(); 
int colorId = buttonColor.getColor();