Example of Android programming to realize user-defined input method function [prevent third-party theft when entering password]

This paper describes the implementation of user-defined input method function by Android programming. Share with you for your reference, as follows:

For Android users, third-party input methods are generally used. However, when entering passwords (especially those related to payment), using third-party input methods has great security risks. At present, many online banking APP and Alipay software will pop up the custom input method when the user enters the password instead of using the system input method directly.

Here is how to implement a simple custom input method. Of course, you can also write a dialog and dozens of buttons for users to input, but it's not professional enough.

(1) First, the rendering:

1. The first two input boxes use a custom input method:

2. The third input box has no settings, so the default input method will be used:

(2) Code introduction:

1. The main page layout consists of three input boxes plus an android.inputmethodservice.keyboardview. Android.inputmethodservice.keyboardview is a component of the system that inherits from view, but it is not under the android.view package, so you need to write the complete package name here.

2. Keyboardview is a container control that displays input methods. Specific input method panel contents need to be set when using.

(1) First, create a new XML directory under res, and then create the file keys_ Layout.xml, the content of the input method panel. Each row represents a row, the keywidth and keyheight of the keyboard attribute represent the size of each key, and 25% P represents 25% of the parent component. The key attribute codes represent the number of the key (this value will be returned in the system callback method to distinguish different keys when clicked), and the keylabel represents the text displayed on the key. There are many other properties that are no longer stated.

(2) For ease of use, create a new class: keyboardbuilder.java, which is used to initialize the custom input method and bind EditText. The code is as follows:

3. Finally, the code of the main activity, which is very simple here.

More readers interested in Android related content can view the special topics of this site: summary of Android view skills, summary of Android development animation skills, summary of activity operation skills of Android programming, summary of Android layout skills, introduction and advanced tutorial of Android development, summary of Android resource operation skills, and Android control usage summary

I hope this article will help you in Android programming.

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