I need programmatically set different icons in layer list by @+id/calendar_day_bottom_icon
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/calendar_date_today_bg"/>
<item android:id="@+id/calendar_day_bottom_icon" >
<bitmap
android:src="@drawable/ic_calendar_journal"
android:gravity="bottom|center" />
</item>
</layer-list>
In code I do next thing
LayerDrawable layerDrawable = (LayerDrawable) cellView.getBackground();
BitmapDrawable drawable = (BitmapDrawable) getResources().getDrawable(R.drawable.ic_calendar_journal_reminder);
layerDrawable.setDrawableByLayerId(R.id.calendar_day_bottom_icon, drawable);
But icon inserts incorrectly.
I want this one:
But there is:
I find the solution with another drawable file:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap
android:gravity="bottom"
android:src="@drawable/ic_calendar_journal" />
</item>
</layer-list>
get drawable
LayerDrawable layerDrawable = (LayerDrawable) ContextCompat.getDrawable(context, R.drawable.calendar_layers);
get LayerDrawable, get layer item and set it to another LayerDrawable.
LayerDrawable cellLayerDrawable = (LayerDrawable) cellView.getBackground();
Drawable drawable = layerDrawable.getDrawable(0);
cellLayerDrawable.setDrawableByLayerId(R.id.calendar_day_bottom_icon, drawable);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With