Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. public static void SetBackground(View view, Drawable icon) {
  2. if (Build.VERSION.SDK_INT >= 16)
  3. Helper.SetBackground(view, icon);
  4. else view.setBackgroundDrawable(icon);
  5. }
  6.  
  7. public class Helper {
  8. public static void SetBackground(View view, Drawable icon) {
  9. view.setBackground(icon);
  10. }
  11. }
  12.  
  13. public static Method getResources;
  14.  
  15. static {
  16. try {
  17. Class<?> class[] = new Class[1];
  18. class[0] = String.class;
  19. getResources= Context.class.getMethod("getResources", class);
  20. } catch (NoSuchMethodException e) {
  21. Log.e(TAG, "getResources is deprecated");
  22. }
  23. }
  24.  
  25. MyClass extends Application { ...}
  26.  
  27. if(MyClass.getResources!= null){
  28. //Do stuff
  29.  
  30. } else {
  31.  
  32. //Fail or do other stuff
  33. }
  34.  
  35. public interface DrawableUtil {
  36. void setBackground(View v, Drawable d);
  37. }
  38.  
  39. public class PreJellyBeanDrawableUtil {
  40. void setBackground(View v, Drawable d) {
  41. v.setBackgroundDrawable(d);
  42. }
  43. }
  44. public class JellyBeanDrawableUtil {
  45. void setBackground(View v, Drawable d) {
  46. v.setBackground(d);
  47. }
  48. }
  49.  
  50. DrawableUtil util;
  51. if (Build.VERSION.SDK_INT >= 16)
  52. util = new JellyBeanDrawableUtil();
  53. else
  54. util = new PreJellyBeanDrawableUtil();
  55. util.setBackground(view, icon);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement