Material-calendarview: DayViewFacade.setSelectionDrawable and DayViewFacade.setBackgroundDrawable cannot work at the same time

Created on 15 May 2016  Â·  2Comments  Â·  Source: prolificinteractive/material-calendarview

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

bug

Most helpful comment

@quentin41500 Thanks for your answer!I seems that you can not use color value in

<item android:drawable="@drawable/show_other"/>

instead.And all of them works just as you said.

All 2 comments

@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

<item android:drawable="@drawable/show_other"/>

instead.And all of them works just as you said.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vincent-etienne picture vincent-etienne  Â·  7Comments

KhanStan99 picture KhanStan99  Â·  4Comments

ghost picture ghost  Â·  4Comments

chuks picture chuks  Â·  6Comments

Xirate picture Xirate  Â·  5Comments