ActionBar uses the application icon to respond to the operation
Call the setDisplayHomeAsUpEnabled () method of the ActionBar class to use the application icon as the navigation bar.
The arrow to the left is automatically added.
Use other icons:
Call the setIcon () method of the ActionBar class.
// Obtain the ActionBar object
ActionBar actionbar = getActionBar ();
// Set the icon
ActionBar. setIcon (R. drawable. ic_launcher );
// Use the icon as the navigation bar
ActionBar. setDisplayHomeAsUpEnabled (true)
The resource ID of this location is android. R. id. home,
Developers can respond to click events with this ID.
Override onMenuItemSelected (or onOptionsItemSelected () method in Activity,
You can respond to click events at this location. The common response method is to return the previous interface or the main interface, using INtent
Activate other Activity components, or call finish () to end the current Activity (when the current Activity ends, the previous Activity returns to the foreground ).
Directly run the Code:
Package com. example. actionbar_test; import android. OS. bundle; import android. annotation. suppressLint; import android. app. actionBar; import android. app. activity; import android. content. intent; import android. view. menu; import android. view. menuItem; public class ActionBar_Activity extends Activity {@ SuppressLint ("NewApi") @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_action_bar _); ActionBar actionbar = getActionBar (); actionbar. setIcon (R. drawable. home_checked); actionbar. setDisplayHomeAsUpEnabled (true) ;}@ Overridepublic boolean onOptionsItemSelected (MenuItem item) {// TODO Auto-generated method stubint id = item. getItemId (); if (id = R. id. action_settings) {return true;} if (id = android. r. id. home) {// click Intent intent = new Intent (this, MainActivity. class); startActivity (intent); finish ();} return super. onOptionsItemSelected (item );}}