How can I access all drawables in android?

前端 未结 4 1064
攒了一身酷
攒了一身酷 2020-12-03 01:58

Only some drawables are accessible via the syntax. For example expander_ic_maximized is not accessible, yet its cle

相关标签:
4条回答
  • 2020-12-03 02:19

    Android SDK has all images unpacked in the %SDK-FOLDER%/platforms/android-*/data/res/drawable-* folder. Just pick desired file and put it into your app resource.

    0 讨论(0)
  • 2020-12-03 02:27

    you just need to add this in your imports list:

    import android.R;
    

    but i will make your own resources will have an error if you want to use it. The error will be something like:

    R. cannot be resolved

    So, I prefer not to import android.R but import *my.own.package*.R;

    then when I can normally use my own resource with R.drawable.*something* without error, and put android.R.*something_default* to use the default android resources.

    well, choosing which one to use, depends in what you need.. :)

    0 讨论(0)
  • 2020-12-03 02:28

    I realize it's a bit more work, but as a workaround you could just set the image resource programatically.

    findViewById(R.id.ImageButton1).setImageResource(android.R.drawable.expander_ic_maximized)

    0 讨论(0)
  • 2020-12-03 02:28

    It's simple. Find the name of your desired icon (e.g., ic_menu_preferences), and paste it into your XML.

    For example, to show the settings icon in the option menu, your XML should be:

    android:icon="@android:drawable/ic_menu_preferences"
    

    That's it. No need to copy to drawable folder. Whenever you write : sign after android, it addresses system resources.

    0 讨论(0)
提交回复
热议问题