开发者

How can I access all drawables in android?

Only some drawables are accessible via the <ImageButton src="@+android:drawable/ syntax. For example开发者_运维百科 expander_ic_maximized is not accessible, yet its clearly at http://androiddrawableexplorer.appspot.com/

its so frustrating to have to download the drawables and manually put them in my drawables folder....any ideas how to get around this???


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.


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)


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.. :)


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜