Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Can't use android.R.drawable as background image for textview

I'm trying to use the android.R.drawable stat_sys_download as the background image for a text view but it's not showing up:

textview.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.stat_sys_download));

If I use a different android.R.drawable like ic_menu_save it works fine:

textview.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.ic_menu_save));  

I can however use stat_sys_download as an icon on a menu option so I know it exists:

menu.add(0, OPTION_MENU_SORTBY, 0, Str.TEXT_SORTBY).setIcon(android.R.drawable.stat_sys_download); 

So why is it that I can use stat_sys_download as an icon but not as a background? Should I copy it into my resources folder and use it that way?

like image 344
odiggity Avatar asked Nov 04 '22 17:11

odiggity


1 Answers

From Google's UI Guidelines for Status Bar Icons (also can be applied towards other drawable elements)

Warning: Because these resources can change between platform versions, you should not reference these icons using the Android platform resource IDs (i.e. status bar 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. In that way, you can maintain control over the appearance of your icons, even if the system's copy changes.

like image 179
javisrk Avatar answered Nov 11 '22 11:11

javisrk