Is there any quick way to know if an image is referenced or used in a Java class or XML layout? For example like if an image.9.png is used in a certain layout. Thanks.
-
you want to know this at run time or in IDE you are using – Vipin Sahu Apr 19 '12 at 07:02
-
In eclipse. I'm cleaning out unnecessary resources, so I'm finding unused images. – Lawrence Gimenez Apr 19 '12 at 07:26
-
@userIsAMonkey Best way for that to look in it Android Lint Warnings. – Herry Apr 19 '12 at 07:29
-
Yup. I was thinking about that and probably the best solution yet. Thanks @Herry – Lawrence Gimenez Apr 19 '12 at 08:12
2 Answers
in Eclipse you cam make Search Like below Step .
First Click your Current Project in which you would like to Search .
Now Press Ctrl+H in windows that will open Search Dialog Window.
Now you want to check bg.png
used in your Project ,Search like below in
@drawable/bg
This will search for all Layout and xml file which use this image.
Now for Search in java file you need to search with it's id which you give in xml file.
R.id.yourimageId
Now in your case you can search your @drawable/image by Ctrl+h Dialog in Eclipse.
EDIT In ADT updated version Like ADT 16 we have lint tool it will give all warning for unused Resource .
Issue: Looks for unused resources
you will find this warning in lint check . for More about Lint Refer this Link Lint Checker SO
-
how if **bg** also represents a shape, layer-list or etc. in folder **drawable**? – waqaslam Apr 19 '12 at 07:04
-
-
-
If we have `bg.xml` in `drawable` then also we can search it for where it is used in xml file of layout .And if bg is png or image then also we can search it . – Herry Apr 19 '12 at 07:18
There's no way to do it via code. However, in Eclipse, if you delete the image (make sure you make a copy first) and build the project, you'll know the spots where you are missing it :)

- 67,549
- 16
- 165
- 178