public class SetBackgroundDrawableDecorator implements DayViewDecorator {
private final Drawable drawable;
public SetBackgroundDrawableDecorator(Context context) {
drawable = context.getResources().getDrawable(R.drawable.bg_cus);
}
@Override
public boolean shouldDecorate(CalendarDay day) {
return true;
}
@Override
public void decorate(DayViewFacade view) {
view.setBackgroundDrawable(drawable);
}
}
public class SetSelectionDrawableDecorator implements DayViewDecorator {
private final Drawable drawable;
public SetSelectionDrawableDecorator(Context context) {
drawable = context.getResources().getDrawable(R.drawable.my_selector);
}
@Override
public boolean shouldDecorate(CalendarDay day) {
return true ;
}
@Override
public void decorate(DayViewFacade view) {
view.setSelectionDrawable(drawable);
}
}
R.drawable.bg_cus is a shape.xml and R.drawable.my_selector is a selector.xml.
if i use
(1)widget.addDecorators(new SetSelectionDrawableDecorator(this));
or
(2)widget.addDecorators(new SetBackgroundDrawableDecorator(this));
works fineï¼›
but
widget.addDecorators(new SetSelectionDrawableDecorator(this),new SetBackgroundDrawableDecorator(this));
works just like (2);
it seems that setSelectionDrawable() will be invalid while using setBackgroundDrawable().
It is a bug?
Android version : 5.11LMY47V.
Library version:com.prolificinteractive:material-calendarview:1.2.1
@wangzhuangzhuang I was able to reproduce it. To fix it, your bg_cus needs to have some transparency.
For example:
This bg_cus will hide my_selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#006BBA"/>
</selector>
This bg_cus will show the other selector background:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#22006BBA"/>
</selector>
This bg_cus will show the background on all the tile. If you want bg_cus to be applied only on selected date, you need to do the same as my_selector:
Final bg_cus:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_shortAnimTime">
<item android:state_checked="true"
android:drawable="#22006BBA" />
<item android:state_pressed="true"
android:drawable="#22006BBA" />
<item android:drawable="@android:color/transparent" />
</selector>
Let me know if this works or not.
@quentin41500 Thanks for your answer!I seems that you can not use color value in instead.And all of them works just as you said.<item android:drawable="@drawable/show_other"/>
Most helpful comment
@quentin41500 Thanks for your answer!I seems that you can not use color value in-
instead.And all of them works just as you said.