Android的 - 如何得到一个应用程序的图标? [英] Android - How to get an icon of an app?
本文介绍了Android的 - 如何得到一个应用程序的图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想显示这样的任务列表 -
I am trying to display a list of task in this way -
图标|应用程序名称|复选框
Icon | ApplicationName | CheckBox
因为我发现没有任何的ListView适配器支持这个,所以我决定开发一个定制的适配器,但我无法获取应用程序的图标。到目前为止,我想这: -
As i found that no listview adapter supports this so i decided to develop a custom adapter but i am unable to fetch the icon of an application. So far i tried this :-
public View getView(int position, View convertView, ViewGroup parent)
{
View v = convertView;
View row = inflater.inflate(R.layout.item, parent, false);
CheckedTextView ctb = (CheckedTextView)row.findViewById(R.id.checkText);
String pkgName = "com.abc.abc";
ctb.setText("bla bla");
ImageView iv = (ImageView)row.findViewById(R.id.image);
List<PackageInfo> pkgs = activity.getPackageManager().getInstalledPackages(0);
for(PackageInfo p : pkgs)
{
if(p.packageName.equals(pkgName))
{
Drawable d = p.applicationInfo.loadIcon(pm);
iv.setImageDrawable(d);
}
}
return row;
}
}
,我相信我试图在这个code一些愚蠢的事。请尽量赶上无论我做错了。
And i am sure i am trying something stupid in this code. Please try to catch whatever i am doing wrong.
感谢。
推荐答案
您可以得到一个应用程序的(包的)图标用:
You can get an app's (package's) icon with:
String pkg = "com.app.my";
Drawable icon = getContext().getPackageManager().getApplicationIcon(pkg);
这篇关于Android的 - 如何得到一个应用程序的图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文