I am writing a Static method that returns the required Drawable by parameter. How can I get Drawable by id without getting Context ? Those. getting only a String ?

 public static Drawable getDrawableByString(Context context, String color) { Drawable retDrawable = ContextCompat.getDrawable(context, R.drawable.round_transparent); switch (color) { case "RED": retDrawable = ContextCompat.getDrawable(context, R.drawable.round_darkred); break; case "BLUE": retDrawable = ContextCompat.getDrawable(context, R.drawable.round_blue); break; } return retDrawable; } 
  • And if so: Drawable retDrawable = Resources.getSystem().getDrawable(R.drawable.round_transparent) ? But in general it is not good. - post_zeew 2:46 pm
  • one
    As an option - get the context from the Application class singleton. So it will be possible to remove the argument and get the context in the method itself - Yuriy SPb
  • anyway, without context, you cannot do anything with this Drawable. That is, you can only display it using the context. So I see no reason to try to clean it. - Vladyslav Matviienko

0