Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void SetBackground(View view, Drawable icon) {
- if (Build.VERSION.SDK_INT >= 16)
- Helper.SetBackground(view, icon);
- else view.setBackgroundDrawable(icon);
- }
- public class Helper {
- public static void SetBackground(View view, Drawable icon) {
- view.setBackground(icon);
- }
- }
- public static Method getResources;
- static {
- try {
- Class<?> class[] = new Class[1];
- class[0] = String.class;
- getResources= Context.class.getMethod("getResources", class);
- } catch (NoSuchMethodException e) {
- Log.e(TAG, "getResources is deprecated");
- }
- }
- MyClass extends Application { ...}
- if(MyClass.getResources!= null){
- //Do stuff
- } else {
- //Fail or do other stuff
- }
- public interface DrawableUtil {
- void setBackground(View v, Drawable d);
- }
- public class PreJellyBeanDrawableUtil {
- void setBackground(View v, Drawable d) {
- v.setBackgroundDrawable(d);
- }
- }
- public class JellyBeanDrawableUtil {
- void setBackground(View v, Drawable d) {
- v.setBackground(d);
- }
- }
- DrawableUtil util;
- if (Build.VERSION.SDK_INT >= 16)
- util = new JellyBeanDrawableUtil();
- else
- util = new PreJellyBeanDrawableUtil();
- util.setBackground(view, icon);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement