Actual difference between TextView and Button

2020-08-11 10:54发布

问题:

Considering the main purpose of a button is to react to a click event, and the fact that both Button and TextView has properties for text, drawable (icon) and click event, what is the actual difference between them, when should you chose one over the other?

回答1:

Looking at the reference docs, the Button class extends the TextView class. From there, the Button adds a few stylistic changes (e.g., default background image, additional padding) to allow quicker adaptation to your designs.

IMO, the one you choose to use should depend on how you want to design your app. If you use the default theme with minimal stylistic changes, Buttons can be quicker to visualize; on the other hand, if you are doing a lot of customization, TextView will let you do that much easier.

**Edit: ** GrepCode shows that from a functionality point of view, there is no difference aside from class name.