How can I convert String to Drawable
问题 I have many icon in drawable folder and I have their name as String. How can I access to drawable folder and change background imageView (or any view) use these name in dynamically. Thanks 回答1: This can be done using reflection: String name = "your_drawable"; final Field field = R.drawable.getField(name); int id = field.getInt(null); Drawable drawable = getResources().getDrawable(id); Or using Resources.getIdentifier() : String name = "your_drawable"; int id = getResources().getIdentifier