Directly rewrite the following three methods in the subclass of the Activity class:
Copy codeThe Code is as follows:
// Rewrite the onCreateOptionsMenu () method. The menu bar is displayed.
@ Override
Public boolean onCreateOptionsMenu (Menu menu ){
GetMenuInflater (). inflate (R. menu. activity_main, menu );
Return true;
}
// The rewrite back button. If you only need the rewrite return button, you can rewrite the onBackPressed () method in the Activity.
@ Override
Public void onBackPressed (){
// TODO Auto-generated method stub
Super. onBackPressed ();
Toast. makeText (MainActivity. this, "onBackPressed !! ", Toast. LENGTH_SHORT). show ();
}
// Rewrite Search button
// The onKeyDown () method. Multiple buttons can be rewritten: Number key, Menu key, and return key.
@ Override
Public boolean onKeyDown (int keyCode, KeyEvent event ){
// TODO Auto-generated method stub
If (keyCode = KeyEvent. KEYCODE_MENU ){
Toast. makeText (MainActivity. this, "Search Menu", Toast. LENGTH_SHORT). show ();
}
Return super. onKeyDown (keyCode, event );
}