BKJIA exclusive translation this article is translated from the foreign language website tutsplus.com "Android interactive experience must know: function button event". All translations are as follows:
Start learning
Each Android device generally provides physical function buttons except letters and numbers, which are generally different from those of different Android manufacturers, for example, Sony only implements three of these function buttons. If these buttons are well designed, they can provide a good interactive experience for the apps being developed.
Android applications are mainly designed based on Activities. I believe most developers are familiar with this design and can learn it in the Official development manual. Today, we are going to learn how to implement the KeyEvent. Callback interface to redefine the function buttons on Android devices and serve our applications.
Constant definition and method of function buttons
The KeyEvent class has multiple defined key constants, which indicate the function buttons in a standard Android device:
Function buttons |
Constant Definition |
Description |
Power |
KEYCODE_POWER |
Enable or wake up a device |
Back |
KEYCODE_BACK |
Back to the previous page) |
Home |
KEYCODE_HOME |
Return to the main menu screen) |
SEARCH |
KEYCODE_SEARCH |
Open a search |
CAMERA |
KEYCODE_CAMERA |
Enable camera function |
VOLUME |
KEYCODE_VOLUME_UP KEYCODE_VOLUME_DOWN |
Adjust volume |
You can find