yannecer / NCalendar

一款安卓日历,仿miui,钉钉,华为的日历,万年历、365、周日历,月日历,月视图、周视图滑动切换,农历,节气,Andriod Calendar , MIUI Calendar,小米日历

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mui10 背景问题

zhaobinsir opened this issue · comments

mui10 没有找到设置背景的方法,Miui10Calendar直接设置backGround 无效,有解决方案吗

已解决 继承InnerPainter, 重写onDrawCalendarBackground(),即可
image InnerPainterChild代码:public class InnerPainterChild extends InnerPainter {

protected Paint mTextPaint;

private Attrs mAttrs;

private Context context;

private ICalendar mCalendar;

public InnerPainterChild(ICalendar calendar,Context context) {
    super(calendar);
    this.mCalendar = calendar;
    this.mAttrs = calendar.getAttrs();
    mTextPaint=getPaint();
    this.context=context;
}

private Paint getPaint() {
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setTextAlign(Paint.Align.CENTER);
    return paint;
}

@Override
public void onDrawCalendarBackground(ICalendarView iCalendarView, Canvas canvas, RectF rectF, LocalDate localDate, int totalDistance, int currentDistance) {
    if (iCalendarView.getCalendarType() == CalendarType.MONTH && mAttrs.isShowNumberBackground) {
        mTextPaint.setTextSize(mAttrs.numberBackgroundTextSize);
        mTextPaint.setColor(mAttrs.numberBackgroundTextColor);
        int alphaColor = mAttrs.numberBackgroundAlphaColor * currentDistance / totalDistance;
        mTextPaint.setAlpha(alphaColor);
        canvas.drawText(localDate.getMonthOfYear() + "", rectF.centerX(), getBaseLineY(rectF), mTextPaint);
        Bitmap bitmap= BitmapFactory.decodeResource(context.getResources(), R.drawable.rilibg);
        canvas.drawBitmap(bitmap,0,0,mTextPaint);
    }
}

//canvas.drawText的基准线
private float getBaseLineY(RectF rectF) {
    Paint.FontMetrics fontMetrics = mTextPaint.getFontMetrics();
    float top = fontMetrics.top;
    float bottom = fontMetrics.bottom;
    // int baseLineY = (int) (rectF.centerY() - top / 2 - bottom / 2);
    float baseLineY = rectF.centerY() - (fontMetrics.bottom - fontMetrics.top) / 2 - fontMetrics.top;
    return baseLineY;
}

}

很赞 ,目前日历只支持属性设置背景颜色bgCalendarColor,图片就需要重新绘制了

希望大佬 更新啊,直接设置属性的方法

@zhaobinsir 更新了5.0版,可以设置背景了