Implementation method of changing color when Android button is pressed

The requirement is to change the color of the button when I press the button, so that the user can feel that he has pressed the button, and when I release it, it will change back to the original color.

Normal:

When pressed:

Some people say that it's great to directly monitor button pressing events. In fact, this can achieve the same effect, but there is a disadvantage. For example, many buttons need this effect, and you have to repeat the same code many times. Therefore, it is still necessary to be universal.

First, create a new folder drawable under the res folder, which is independent of the resolution:

Create an XML file below: login_ button_ selector.xml

Then add the following in the string.xml file under the value folder:

Finally, add the following for the button:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>