Skip to content

Instantly share code, notes, and snippets.

@TheFinestArtist
Created July 25, 2015 14:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheFinestArtist/760aeb8dbdf2cd244512 to your computer and use it in GitHub Desktop.
Save TheFinestArtist/760aeb8dbdf2cd244512 to your computer and use it in GitHub Desktop.
ViewHelper.java
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.View;
/**
* ViewHelper
*
* Created by TheFinestArtist
*/
public class ViewHelper {
public static void setBackground(Context context, View view, int id) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
view.setBackgroundDrawable(context.getResources().getDrawable(id));
else
view.setBackground(context.getResources().getDrawable(id));
}
public static void setBackground(View view, Drawable d) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
view.setBackgroundDrawable(d);
else
view.setBackground(d);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment