解决LikeButton不兼容23以下版本的问题

在网上找到一个实现点赞特效的项目,点赞可以实现发散星星的效果,但是引用到自己的项目中出现不兼容的情况,最后发现23以下版本不兼容,如果需要在23以下版本使用,需要自己改动代码。原项目链接: https://github.com/jd-alexander/LikeButton  

改动步骤:
       1、在gradle中引用jar包:  compile  'com.android.support:appcompat-v7:22.2.0'   
                         compile  'com.android.support:support-v4:22.2.0'
   
       2、找到LikeButton类,修改里面报错的方法如下:
public void  setExplodingDotColorsRes ( @ColorRes  int  primaryColor @ColorRes  int  secondaryColor) {
//原代码
//dotsView.setColors(ContextCompat.getColor(getContext(),primaryColor), ContextCompat.getColor(getContext(),secondaryColor));
//改为以下代码
dotsView .setColors( context .getResources().getColor(primaryColor) context .getResources().getColor(secondaryColor)) ;
}

public void  setCircleStartColorRes ( @ColorRes  int  circleStartColor) {
 this . circleStartColor  = circleStartColor ;
//原代码
//circleView.setStartColor(ContextCompat.getColor(getContext(),circleStartColor));
//改为以下代码
circleView .setStartColor( context .getResources().getColor(circleStartColor)) ;
}

public void  setCircleEndColorRes ( @ColorRes  int  circleEndColor) {
this . circleEndColor  = circleEndColor ;
//原代码
//circleView.setEndColor(ContextCompat.getColor(getContext(),circleEndColor));
//改为以下代码
circleView .setEndColor( context .getResources().getColor(circleEndColor)) ;
}

3、找到Utils类,修改里面的方法:
 
 
//去掉
/* private static Bitmap getBitmap(VectorDrawableCompat vectorDrawable, int width, int height) {
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
vectorDrawable.draw(canvas);
return bitmap;
}*/

public static Bitmap  getBitmap(Drawable drawable , int width , int height) {
if (drawable  instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap() ;
/*去掉else if (drawable instanceof VectorDrawableCompat) {
return getBitmap((VectorDrawableCompat) drawable, width, height);
} */ else if (drawable  instanceof VectorDrawable) {
return  getBitmap((VectorDrawable) drawable width height) ;
else {
throw new IllegalArgumentException( "Unsupported drawable type") ;
}
}

4、修改 likeview.xml文件中的使用的控件的路径名称,改为引用自己工程里的

5、可以在项目中使用LikeButton控件了,具体属性可以参照上面的链接,如果想做一些自定义的修改可以在代码中修改,可以设置背景色,隐藏圆view,可以指定发散半径等。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值