Android customized EditText to realize Taobao login function

This article mainly customizes EditText. When EditText has text input, the delete icon will appear. Click the delete icon to clear the text. Secondly, the return of password is processed, and * is used to replace the one provided by the system.

First look at the renderings:

Overall layout UI:

Custom EditText class

Because of the custom EditText, it is natural to integrate EditText

Then add construction methods so that they can be referenced in XML.

The next step is to set your own EditText style and add the style you want. It is implemented in the init () method.

Implementation process of init() method: [2] the parameters are: dr.mdrawableright, the definition deletion button is on the right of EditText, and the upper left and lower right of the setting Icon: mcleardrawable.setboundaries (0, mcleardrawable. Getinternalwidth(), mcleardrawable. Getinternalheight());

Since the monitoring event cannot be directly set for EditText, the click position is recorded to simulate the click event, and only the left and right clicks of the fish icon are recorded.

Judge whether there is text in the input box, and dynamically set the display and hiding of delete icons.

If there is text in the input box, draw the delete icon for a long time

When the content of the input box changes, the delete icon is dynamically changed

This is done: when there is no text in the attribute box, the delete icon is hidden. When there is text input, the delete icon is displayed. Click the delete icon to empty the text content.

Custom inputtype returned as "*"

Set the password style to inherit the passwordtransformationmethod class, and then implement the charsequence method to modify the return value of charat to "*".

Then initialize the control in the main program and set the line of Android: password = "true" in the layout to dynamically set the return style of password input in the code.

Summary:

Add delete icon listening in the user-defined EditText. Since it cannot be set directly, the click event is simulated by recording the pressed position. The overall implementation idea is to draw a delete icon on the right side of EditText, and then dynamically set display or hide. By setting listening events, it can dynamically display and clear the text in the text box. When customizing the password return style, it mainly inherits the passwordtransformationmethod class, implements the charsequence method, and replaces the input style with custom.

Click to download the source code

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

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
分享
二维码
< <上一篇
下一篇>>