Skip to content

Commit

Permalink
Use ContextCompat to avoid exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
sami286 committed Jan 11, 2019
1 parent c6aed9d commit e57a6f5
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions toasty/src/main/java/es/dmoral/toasty/ToastyUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.view.View;

/**
Expand Down Expand Up @@ -50,16 +51,10 @@ static void setBackground(@NonNull View view, Drawable drawable) {
}

static Drawable getDrawable(@NonNull Context context, @DrawableRes int id) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
return context.getDrawable(id);
else
return context.getResources().getDrawable(id);
return ContextCompat.getDrawable(context, id);
}

static int getColor(@NonNull Context context, @ColorRes int color){
if (Build.VERSION.SDK_INT >= 23)
return context.getColor(color);
else
return context.getResources().getColor(color);
return ContextCompat.getColor(context, color);
}
}

0 comments on commit e57a6f5

Please sign in to comment.