Implementation code of Android imitation wechat custom numeric keyboard

This paper introduces the implementation code of Android imitation wechat custom numeric keyboard, which is shared with you. I hope it will be helpful to you

Final effect:

The idea of implementing this custom keyboard is very simple:

With ideas, it is not difficult to realize.

1. Implement the XML layout of the keyboard

Grid style layout can be realized by GridView or recyclerview. In fact, it is more convenient to use GridView. However, in order to be more familiar with the usage of recyclerview, I choose to use recyclerview here.

Recyclerview is used to realize keyboard layout, and the relativelayout above is used to realize the click event of folding the keyboard.

2. Implement keyboard layout in the code, fill in data and add click events

We create a new class, keyboardview, which inherits from relativelayout, associates the above layout file, and then do some initialization operations: fill the recyclerview with data, set the adapter, set the appearance and disappearance animation effects, and write some methods that will be used.

The adapter contains very simple code, which will not be posted here. I will give the source code download address at the end of the article.

So far, the custom numeric keypad has been basically written, but the most important thing is to use it in combination with EditText.

3. Use in combination with EditText

1. Disable the system soft keyboard

I found some methods on the Internet, but when I click EditText, the system soft keyboard will still pop up. Finally, this method is found. The soft keyboard is forced not to pop up by reflection, and the effect is good.

2. Handle the click events of each key

The logic is also very simple. You can see it from the code. The final effect is what the first picture looks like.

This keyboard is very simple, and then plan to write a WeChat or Alipay payment password entry layout.

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