Android imitation wechat @ friend function input @ jump and delete the whole block

Recently, when doing the chat function, there was a need to imitate the function of wechat as @ friend. I thought it was very simple, but when doing this, I found that it was a little different from what I imagined. What is the whole block deleted and the block editable? In short, the function of adding @ is very simple, but it still took some effort to do the same as that of wechat. The following is a demo for reference only, Prevent forgetting

Last rendering first

That's the function

1. Analyze requirements

Enter @ to jump to the contact interface and select one or more friends to return to the current interface

Press the backspace key to delete the whole block

The content in the block can be edited. After editing, there will be no @ function, just simple text

2. Start coding

Since it is text input, first inherit EditText and customize a control

Where do you start? First, complete the requirements of turning into blocks,

Accidentally see this project https://github.com/g707175425/CloudEditText , that's what he wrote

Here we remember the usage of spanablestring. It can set pictures, set the background and foreground of text at will, and a series of cool effects. In addition, it only needs a textview. If you need to deeply understand span, you can use Baidu and Google. For the advanced usage of span, you have the following implementation

That's what I wrote at first

Now that the whole block addition has been completed, let's start to delete the whole block. At the beginning, I wrote it by imitating the cloudedittext above, but I found that I would use various problems, so I thought of a method

The above meaning is that if you delete a character in EditText, judge whether the previous one is a span. If it is a custom span, delete the span together. For this, I can test various operations

The last is to get the list of people who need @

Finally, I'll put an address generously. See for yourself

https://github.com/ddssingsong/AtFriend

summary

The above is the Android imitation wechat @ friend function input @ jump and delete the whole block introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

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