Using Enums to customize the UI in Android?
Sep 18, 2022
If we use enums correctly, we can write less code and get better results. At the same time, we prevent code pollution.
First of all, we define the our colors into colors.xml. This color tells us that green colors are success, red colors are error and gray colors are information colors.
After defining, I added three icons to the project and designed the layout as below and also defined some strings for each case.
Now, let’s create a new enum to customize this view.
How to use;
- MessageType.INFO
- MessageType.SUCCESS
- MessageType.ERROR
Thanks for reading, all the best… :)