S
S
speckolya2017-04-02 15:10:29
Android
speckolya, 2017-04-02 15:10:29

android studio. How to make such a button with a message counter (photo inside)?

e14c1acfac884feab7d992b5bc72cb19.jpg
It is impossible to fasten the counter of messages to the button.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Vashchenko, 2017-04-03
@speckolya

You can do it quite simply:
Use a RelativeLayout, inside it is a button with an icon, as well as a picture in the form of a circle and a TextView. It is necessary to take into account two-digit numbers and the fact that they will be wider, i.e. needs to be aligned in the middle. If the counter is zero, just make the TextView and ImageView GONE visability and that's it.

A
Andrey Myvrenik, 2017-04-02
@gim0

Two options come to mind. The first is more difficult, but the most effective and correct. The second one is simpler, but crap, and it will do if you just need to quickly rivet something.
1. By overwriting the onDraw() method in a specific View of the button. Adding a circle, shading, and text is easy.
2. Wrap the button in some ConstraintLayout/RelativeLayout and position the TextView with the number and the corresponding background from res/drawables relative to this button.
The only problem is with the font, it is clearly non-standard and you need to think about it separately. Adding custom fonts to the APK usually has a negative impact on the final size of the application.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question