ActionBar of AndroidUI Components
I haven't written a blog post for a while. If I find that my blog is not complete, I will use the AndroidUI component. I will update it as soon as possible. Well, let's not talk about it. Let's take a look at ActionBar today.
According to the previous style, knowledge points are in the source code in the form of code annotations.
Package com. gc. actionbardemo;/*** 1. ActionBar is one of the important updates of Android3.0. The ActionBar is located at the top of the traditional title bar * That is, the displayed screen. The ActionBar displays the application icon and Activity title, that is, the content displayed at the top of the application * program. In addition, activity items can be displayed on the Right of ActionBar. * 2. ActionBar provides the following functions * (1) display menu items of the option menu (display menu items as Action items) * (2) use the program icon to return to the Home screen or navigate up * (3) provide interactive View as Action View * (4) provide a Tab-based navigation mode, it can be used to switch multiple Fragment * (5). It provides a drop-down Navigation Mode * 3. If you want to disable ActionBar, you can set the topic of the application to Xxx. noActionBar * 4. Once ActionBar is disabled, this Android app cannot use ActionBar * 5. In actual projects, it is generally recommended to use code to control the display and hiding of ActionBar, actionBar * provides the following methods to control display and hide. * Show (): show ActionBar * hide (): hide ActionBar */import android. OS. bundle; import android. app. actionBar; import android. app. activity; import android. view. menu; import android. view. view;/***** @ author Android General **/public class ActionBarTest extends Activity {private ActionBar actionBar; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_action_bar_test); // obtain the ActionBar of the Activity. // This code returns ActionBaractionBar = getActionBar ();} only when the ActionBar is not closed for the application topic ();} // define the event handling method public void showActionBar (View source) for the "show ActionBar" button {// display ActionBaractionBar. show () ;}// defines the event handling method public void hideActionBar (View source) for the "Hide ActionBar" button {// hides ActionBaractionBar. hide ();}}
The layout file corresponding to the Activity is activity_action_bar_test. The Code is as follows:
The effect is demonstrated as follows: