When we use the Android phone, we often find that the Actionbar in the application is very different from the actionbar we normally use. Simply put, the other application of the Actionbar why so gorgeous, their own application of the Actionbar is so lame? I have had time to study the related questions about Actionbar.
First of all, let's take a look at what we said about "tall" Actionbar:
Look at the Android documentation and Actionbar implementation of the source code, found that Actionbar can be customized (ps:google or think very thoughtful, worthy of the Great God level programmer), see here everyone to Actionbar mystery has been announced, And then we'll see how it's going to come true.
Package Com.jony.actionbarccustom;import Android.app.actionbar;import Android.app.activity;import Android.os.bundle;import Android.view.menu;import Android.view.menuitem;import Android.view.View;import Android.view.view.onclicklistener;import Android.widget.toast;public class Mainactivity extends Activity {@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Custom ActionBar final ActionBar ActionBar = Getactionbar (); Actionbar.setdisplayoptions (Actionbar.display_show_custom); Actionbar.setcustomview (R.layout.actionbar);//Custom ActionBar layout Actionbar.getcustomview (). Setonclicklistener (New Onclicklistener () {//listener event @Override public void OnClick (View arg0) {switch (arg0.get Id ()) {case r.id.back:showtoast (r.string.finish); Finish (); Break Default:break; } } }); } @Override Public boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu, this adds items to the Actio n Bar if it is present. Getmenuinflater (). Inflate (R.menu.actionbar_menu, menu); Use code to dynamically control the display state of the MenuItem or XML definition MenuItem display state/* MenuItem share = Menu.finditem (R.id.share); MenuItem undo = Menu.finditem (R.id.undo); MenuItem redo = Menu.finditem (R.id.redo); MenuItem save = Menu.finditem (R.id.save); Share.setshowasaction (menuitem.show_as_action_always); Undo.setshowasaction (menuitem.show_as_action_always); Redo.setshowasaction (menuitem.show_as_action_always); Save.setshowasaction (menuitem.show_as_action_always); */return true; } @Override public boolean onoptionsitemselected (MenuItem item) {switch (Item.getitemid ()) {case R.I D.undo:showtoast (R.string.undo); Break Case R.id.redo:showtoast (R.string.redo); Break Case R.id.save:showtoast (R.string.save); Break Case R.id.share:showtoast (R.string.share); Break Default:break; } return super.onoptionsitemselected (item); } private void Showtoast (int msg) {Toast.maketext (Getapplicationcontext (), MSG, Toast.length_short). Show (); }}
Well, the specific code is relatively simple is no longer elaborated, look at:
Source