728x90
반응형
똑같이 생긴 아이콘인데, 색상만 바꿔서 사용해야 할 때가 있을 것이다.
검정 배경 안에 있던 흰색 뒤로가기 버튼과
흰색 배경 안에 있던 검은색 뒤로가기 버튼은
똑같이 생겼고, 똑같은 기능을 한다. 다만 색만 바뀌었을 뿐.
이런경우, 새로운 drawable을 생성하지 않아도 tint 기능을 이용하면 손쉽게 색상을 바꿀 수 있다.
icon_back_white 라는 drawable의 색상을 변경하여 naviBtn 이라는 이미지뷰에 넣어보겠다.
ImageView naviBtn = findViewById(R.id.navi_btn);
Drawable drawable = DrawableCompat.wrap(getResources().getDrawable(R.drawable.icon_back_white));
drawable.mutate();
DrawableCompat.setTint(drawable, getResources().getColor(R.color.colorPrimary));
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
naviBtn.setBackground(drawable);
원리? 모른다. 그대들도 그렇게 궁금하진 않지 않은가.
icon_back_white 라는 drawable의 색상을 R.color.colorPrimary에 저장된 색상으로 교체하여 naviBtn 이라는 이미지 뷰의 백그라운드로 변경하였다.
뭐.. 잘 된다.
728x90
반응형
LIST
'Android' 카테고리의 다른 글
Android 무선 디버깅 (ADB Debug) (0) | 2021.02.16 |
---|---|
Android MVVM 패턴 스터디 1회차 (0) | 2021.02.03 |
Android 상태바 색 바꾸기 (1) | 2021.02.02 |
Android 클래스 생성자, Get & Set 함수 쉽게 만들기 (0) | 2021.02.01 |
Android Recyclerview list 만들기 (0) | 2021.02.01 |