How to add a button to the "extends View" class?

Can I add a button to a class that extends the view? "public class josh extends View" "If not, how can I combine a button into a view when it is referenced in my main action? uhg, please help ....

+4
source share
2 answers

Two ways:

  • You have a button and a custom view in the form of FrameLayout children , with which the button can be drawn above your custom view.

  • You do not have a real button. Instead, draw something that looks like a button, touch touch events, especially if they are within its size, etc. This is more suitable for something like a game.

I believe that you can do # 2, but have a subclass of Button, make a drawing so that it runs exactly the same as a regular button, and just positioned / depends on your user view, but I don’t know how to do it.

+1
source

If you want to add a button to the view at runtime check out this preivoius question ... How do I add a button control to an xml view in an Android environment?

0
source

Source: https://habr.com/ru/post/1398728/


All Articles