在网上找到一个实现点赞特效的项目,点赞可以实现发散星星的效果,但是引用到自己的项目中出现不兼容的情况,最后发现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,可以指定发散半径等。