내 체크 박스의 배경이 drawable xml을 통해 지정되었으며 코드를 통해이 항목의 색상을 변경하고 싶습니다. 안드로이드에서 다른 컨트롤은 색상을 설정하는 다른 방법이있는 것 같습니다. 드로어 블/사진 custom_checkbox.xml에서xml에 지정된 체크 박스 드로어 블의 색상을 변경하는 방법은 무엇입니까?
<Checkbox android:button="@drawable/custom_checkbox" />
:에
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/checked" />
<item android:state_checked="false" android:drawable="@drawable/unchecked" />
</selector>
대부분의 답변은 SO 위의 솔루션에서 중지합니다. 다음 코드를 통해 색상을 변경할 수 있지만이 코드는 특정 API 레벨 (예 : 레벨 17)에서 작동하지 않습니다. 나는 전반적으로 효과가있는 것을 원합니다.
Drawable d = DrawableCompat.wrap(checkbox.getBackground());
DrawableCompat.setTint(d, newColor);
가능한 중복에 http : // 유래. com/questions/39475790/android-tablayout-icon-color-doesnt-change-when-dragging) –
중복 된 것 같지 않습니다. 확인란이 아닌 탭에 대해 묻습니다. 솔루션에는 예제에 레이어 목록도 있는데, 그렇지 않습니다. – Boon
예. 이 스레드에서 허용되는 대답은 모든 API 수준에서 드로어 블 상태를 채색하는 방법을 보여줍니다. –