开发者

How can I dynamically add new icons to Android's main menu grid from Java?

开发者 https://www.devze.com 2023-02-07 07:31 出处:网络
I have an application that I\'d like to have multiple icons in the launcher\'s开发者_如何学JAVA main menu grid but only under certain conditions. For instance, I want to show icon A and icon B but onl

I have an application that I'd like to have multiple icons in the launcher's开发者_如何学JAVA main menu grid but only under certain conditions. For instance, I want to show icon A and icon B but only if the phone is running Android 2.2 because icon B uses a Froyo feature, so I don't want icon B showing up if on a pre-Froyo device.

Is there a way in Java to programmatically add the main menu icon? I don't want it in the manifest file as this isn't flexible at run time... at least not as far as I am aware. This would allow me to either check for some functionality, API, user preference, or a flag in the app.


What about declaring both activities in the manifest, but then enabling / disabling them as needed using PackageManager.setComponentEnabledSetting()?

Good luck

Tom


I'm not aware of a way to change that at runtime. You could either release two versions of the app, one for pre-froyo and one for after if they are sufficiently different, or check out this article on various ways to do backward compatability within a single app.

0

精彩评论

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