2013-06-13 108 views
1

我需要獲取我的應用程序圖標的int id。有什麼辦法可以做到這一點?獲取應用程序圖標Id - Monodroid

我知道在PackageManager中有GetApplicationIcon,但是這返回一個drawable。我怎樣才能得到drawable的Id?

Drawable drawable = ApplicationContext.PackageManager.GetApplicationIcon(applicationInfo); 

我想通過在Android中所有的資源循環的,但我不知道怎麼了,我認爲這將是昂貴的。任何有效的方式,我可以得到圖標ID?

編輯:我明白,我可以很容易地從R.drawable.myicon獲得資源ID,但我希望通過使用PackageManager或ApplicationContext.Resources獲取Id。

編輯#2:我明白了。請參閱下面的答案。

+0

檢查:獲取應用程序圖標在安卓(http://stackoverflow.com/questions/4600740/getting-app-icon-in-android) –

回答

1

好的,我明白了。

Intent intent = context.PackageManager.GetLaunchIntentForPackage(context.PackageName); 
ResolveInfo resolveInfo = context.PackageManager.ResolveActivity(intent, PackageInfoFlags.MatchDefaultOnly); 
int appIcon = resolveInfo.IconResource; 
+0

請把它標記爲一個答案,如果你的問題解決了您的問題:http://meta.stackexchange.com/a/5235 – Cheesebaron

1

那麼,因爲它是你的應用程序,你可以看看你的清單。您的圖標出現在<application>標記中,android:icon屬性中。看看這個文件,看看它說了什麼。

你不需要編程,只需要自己做一次。

3

R.drawable.ic_launcher(或其他名稱,你給它)應該代表你需要的id。

相關問題