Use of Actionbar
1. Start Actionbar (by default it is enabled)
1.1 The theme for setting apps in Android Profile (Androidmanifest.xml) is * * *. Noactionbar
1.2 Controlling the startup of Actionbar in code
The book is written in Getactionbar (), but I never get it when I try it, Actionbar has always been empty.
Problem solving: https://stackoverflow.com/questions/6867076/getactionbar-returns-null(different activity to be obtained in different ways??? )
Getsupportactionbar can successfully obtain Actionbar;
Public classMainactivityextendsappcompatactivity {ActionBar ActionBar; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); //Get ActionbarActionBar =Getsupportactionbar (); LOG.V ("Z", Getsupportactionbar () + ""); } Public voidHideactionbar (view view) {actionbar.hide (); } Public voidShowactionbar (view view) {actionbar.show (); }}
The onclick event can be registered directly in the button in the layout page ***********
< Button Android:layout_width = "Wrap_content" android:layout_height= "Wrap_content" android:text= "Hideactionbar" android:onclick= "Hideactionbar"/>
2. Use Actionbar to display menu options
The difference between 2.1 app:showasaction and android:showasaction: http://www.cnblogs.com/liaojie970/p/5718901.html
2.2 Resource files are written, but not shown on Actionbar:
This is a problem, I don't understand,,,,
The problem found a solution: http://blog.csdn.net/huwei0518/article/details/48834795
Menuitemcompat. setshowasaction (Menu.finditem (r.id. Action), Menuitemcompat. show_as_action_always);(added a piece of code)
/** *Load Menu* * @param menu * @return * *
@Overridepublic boolean Oncreateoptionsmenu (Menu menu)
{
Menuinflater Inflater =New Menuinflater (this);//LoadingR.menu.my_menu corresponding menu , and add to menu Span style= "color: #808080; Font-style:italic; font-family: "Arial" "> Inflater.inflate (R.menu.actionbar, menu);
Menuitemcompat. setshowasaction (Menu.finditem (R.id.action), Menuitemcompat. show_as_action_always);
return < Span style= "color: #660e7a; Font-weight:bold "> Super.oncreateoptionsmen U (menu); < Span style= "color: #000080; Font-weight:bold "> < Span style= "color: #660e7a; Font-weight:bold ">
} /span>
Overflow is the three points above Actionbar, the menu will appear after clicking
< Span style= "color: #000080; Font-weight:bold "> < Span style= "color: #660e7a; Font-weight:bold "> /span>
< Span style= "color: #660e7a; Font-weight:bold; Font-style:italic "> < Span style= "COLOR: #ff0000" > This problem took a lot of time to find a solution, but the principle is not very understand,,, (the cause of this problem seems to be V4 and V7 problem,, import Android.support.v4.view.MenuItemCompat;
import Android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity; )
< Span style= "COLOR: #808000" > < Span style= "COLOR: #808080" > < Span style= "color: #808080; font-family: "Arial" "> < Span style= "COLOR: #ff0000" > code reference: https://www.aliyun.com/jiaocheng/71385.html
3
Android interface Programming-using the Activity Bar (ActionBar)