У меня есть переключатель, который имеет как текст, так и изображение. Я пытаюсь изменить цвет изображения при нажатии кнопки, применяя цвет поверх него, как оттенок. Я пытался использовать android:state_checked="true"
, но это не позволяет мне применять цвет поверх изображения.
Я также пытался сделать это программно с помощью:
RadioButton radioButtonShare= (RadioButton) findViewById(R.id.image_share);
radioButtonShare.getButtonDrawable().setColorFilter(getResources().getColor(R.color.colorPrimaryDark), PorterDuff.Mode.SRC_ATOP);
Но он вылетает с нулевым исключением...
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.drawable.Drawable.setColorFilter(int, android.graphics.PorterDuff$Mode)' on a null object reference
Любезно помочь
Переключатель
<RadioButton
android:id="@+id/image_share"
style="@style/style_radiobutton"
android:layout_height="match_parent"
android:drawableTop="@drawable/selector_image_share"
android:text="@string/edit_share" />
@drawable/selector_image_share
<item android:drawable="@drawable/viewer_ic_share" android:state_checked="true" />
<item android:drawable="@drawable/viewer_ic_share" android:state_pressed="true" />
<item android:drawable="@drawable/viewer_ic_share" />