4

I want to select the a standard Android menu icon based on the current Android version the phone is running.

Example icons:

enter image description here

Remember! I do not want drawables for this purpose, I do want the correct icon based on the devices API.

Is this possible?

Curtain
  • 1,972
  • 3
  • 30
  • 51
  • 1
    the android.R.ic_more resource or whatever? – Robby Pond Mar 18 '11 at 21:39
  • 3
    Unless *all* of your menu icons will come from the OS, you do not want to go this route. Device manufacturers can and do change these icons. If all of your icons come from the OS, then they will all be consistent. But if you are mixing some OS icons and some of your own, then they will not be consistent (your look vs. the look of device X's), and your app will look unprofessional. Internal consistency within the app is more important than external consistency with the device. So, if you have your own icons, copy the Android ones you want into your project. – CommonsWare Mar 18 '11 at 21:45
  • Related posts - [How to use default Android drawables](https://stackoverflow.com/q/3201643/465053), [Where are all the standard Android icon resources?](https://stackoverflow.com/q/7352898/465053), & [Standard Android menu icons, for example refresh](https://stackoverflow.com/q/2687027/465053) – RBT Aug 10 '18 at 02:58

2 Answers2

7

What's wrong with using drawables? Icons are drawables. If you use the R.android.drawable.* drawables, you'll get the appropriate image based on your phone (Sense, stock Android 2.0, stock Android 2.3, etc).

EboMike
  • 76,846
  • 14
  • 164
  • 167
  • 1
    I don't think you should do this, there is no guarantee that in future versions of Android drawables with the same name will exist. You should copy the drawables into your own project, and add API version specific versions if necessary. – Joseph Earl Mar 18 '11 at 22:39
  • 1
    @Joseph: Um, no. Copying them is exactly the wrong approach - you'd have to obtain them from every possible Android version (they keep changing) and from every possible customized UI (Sense, MotoBlur, TouchViz). They're defined in the Android SDK (http://developer.android.com/reference/android/R.drawable.html), so they're guaranteed to stay. – EboMike Mar 18 '11 at 22:59
  • As a side note, some of the default drawables are marked as private in the sdk. Unfortunately this means that you will have to copy certain menu icons into your project (Refresh is one, I think) in order to use them. – David Underwood Mar 19 '11 at 00:55
  • 1
    @JosephEarl was right whereas you, EboMike, are definitely wrong. Your approach is exactly the wrong one, as Google says in the docs: `Because these resources can change between platform versions, you should not reference these icons using the Android platform resource IDs (i.e. menu icons under android.R.drawable). If you want to use any icons or other internal drawable resources, you should store a local copy of those icons or drawables in your application resources, then reference the local copy from your application code.` – caw Sep 21 '12 at 12:39
  • @EboMike Perhaps you may be guaranteed files with those names will exist, but you have no guarantee what size/aspect ratio etc they are! – Joseph Earl Sep 21 '12 at 15:44
4

Take a look here, you have to use android.R.drawable.<name> to use them.

tbruyelle
  • 12,895
  • 9
  • 60
  • 74