Change the launch icon

Dynamic replacement of application Icon


Product: Can we dynamically change the App's Icon in Launcher?

Development: No
Product: Can we dynamically change the App's Icon in the Launcher
Development: No
Product: Can we dynamically change the App's Icon in the Launcher
Development: No
Product: We can dynamically change the App's Icon in the Launcher
Develop: Let me think ...

Principle 1 - activity-alias

    In AndroidMainifest, there are two properties:


    In addition, there is an activity-alias attribute, which can be used to create multiple different entries. I believe that developers who have done system Setting and Launcher development should have seen a lot in the source code of the system.

Principle 2 - PM.setComponentEnabledSetting

    PackageManager is a general class that can manage all system components. Of course, if Root is used, you can also manage all components of other apps. Some system optimization tools disable some background services in this way.

    It's very simple to use:


    According to the two flags PackageManager.COMPONENT_ENABLED_STATE_ENABLED and PackageManager.COMPONENT_ENABLED_STATE_DISABLED and the corresponding ComponentName, you can control whether a component is enabled.

Change Icon dynamically

    With the above two principles, there is only a problem of thinking to realize the dynamic replacement of Icon.

    First, we create an Activity as the default entry with the default image, and then create a double 11 activity-alias pointing to the default Activity with the double 11 image, and then create a double 12 activity-alias, Pointing to the default Activity with a picture of double 12... blah blah blah.


    Wait, there is a problem with this, that is, 3 entries will be displayed on the Launcher, so by default, we will disable these activity-alias first, and then enable them when they are used.



    OK, after disabling the default Activity and enabling the activity-alias of Double 11, the result remains the same as the default Activity, but the icon has changed.

Depending on the ROM, after disabling the component, after a while, Launcher will automatically refresh the icons.

    Refer to the following figure for the effect.



As you all know, December 14th is the GDD Shanghai Developers Conference. Last night, GDG finally released the conference materials. Everyone can enjoy it. I put all the resources I think are very good on the online disk. Everyone You can take what you need, the address is as follows:

Link: https://pan.baidu.com/s/1jHMrU4m Password: rjdu

At the same time, the video of the conference has also been released, you can watch the review:

http://list.youku.com/albumlist/show?id=28973499&ascending=1&page=1

Finally, it is also to promote my new course - the art of Android animation development . Click on the original link to view the specific information.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326394504&siteId=291194637