Android two methods to achieve long press return key exit
Android long press the return key to exit
background
Usually, it is common to press the return key twice within a certain time interval to exit the application, and there will be a corresponding prompt for the first click. There are many online materials. Write here and press the return key to exit.
realization
There are two common implementation schemes:
Override the dispatchkeyevent (keyevent event) method
Override onkeydown (int keycode, keyevent event) method
Scheme I
The code is very simple. If you press the return key and press it for a long time, you will exit.
Scheme II
This scheme is recommended. You can modify the number of times of event. Getrepeatcount() = = in else if to modify the long press time. When event. Getrepeatcount() is 0, it means one click. When the number > = 1, it means long press. The larger the value, the longer the press time. This scheme is recommended because it can remind the user when clicking the back button for the first time.
Postscript
Originally, I was going to sort out more information and send it out together. Nuggets just released the tool in the internal test. Here, I'll write an article to try how it feels. The experience is still great. The following are personal opinions:
advantage:
Disadvantages:
Generally speaking, there are basic functions, and the interface is relatively clean. This is both an advantage and a disadvantage. Relatively speaking, it is more suitable for people who memorize markdown grammar.
Finally, take a picture to see the writing interface:
Thank you for reading, hope to help you, thank you for your support to this site!