再弄Android应用程序的图标资源ID [英] Get resource ID of the icon of another android application
本文介绍了再弄Android应用程序的图标资源ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法让在资源ID其他Android应用程序的图标? (例如, com.android.systemui.R.drawable.ic_xxx
)
Is there a way to get the resource ID of the icon of another android app? (ex. com.android.systemui.R.drawable.ic_xxx
)
我试过 context.getApplicationInfo()。图标
,但它返回一个长整型。
这可能吗?
I tried context.getApplicationInfo().icon
but it returned a long integer.
Is this possible?
感谢
推荐答案
您可以通过使用获得应用程序的可绘制
图标:
You can get the Drawable
icon of an app by using:
Drawable icon = getPackageManager().getApplicationIcon( PACKAGE_NAME );
如果你有兴趣在自己的应用程序的可绘制的资源ID,试试这个:
If you are interested in the resource ID of a Drawable of your own app, try this:
int resourceID = getResources().getIdentifier( DRAWABLE_NAME , "drawable", PACKAGE_NAME );
或者,如果你关心性能,这个版本是更快,但使用反射:
Or, if you care about performance, this version is quicker, but uses reflection:
try {
Class resource = R.drawable.class;
Field field = resource.getField( DRAWABLE_NAME );
int drawableId = field.getInt(null);
} catch (Exception e) {}
这篇关于再弄Android应用程序的图标资源ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文