Detailed explanation and example code of Android activity bar actionbar
Detailed explanation of Android activity bar actionbar
Figure I
@H_ 502_ 27@
Actionbar summary of its functions
Figure 1 using actionbar to display option menu items
menu_ Mainxml code
Enable program icon navigation
How to add an action view
Figure 3 tab navigation using actionbar
Figure 4 Fragment support before Android 30
Figure 5 implementation of drop-down navigation using actionbar
Actionbar is one of the important updates for Android 3.0. So now, as long as the target version is higher than 11, the actionbar will be started by default.
Summary of actionbar's functions:
Hide the actionbar. Friends who have used it should know that you can close the actionbar by directly defining noactionbar in androidmanifest.xml. However, if you close the actionbar in this way, you can't use the actionbar in the future. Therefore, we generally use the second code hiding method to operate the actionbar:
1.getActionBar(); 2. Show(): show actionbar 3. Hide(): hide actionbar
Figure 1 using actionbar to display option menu items
menu_ Main.xml Code:
Enable program icon navigation
How to add an action view
In addition to ordinary action items, ordinary UI components can also be displayed on the actionbar in the following two ways:
1. When defining an action item, use the Android: actionviewclass property to specify the implementation class of the action view. 2. When defining an action item, use the Android: actionlayout property to specify the view corresponding to the action view
Figure 2 activity code area:
menu_ Main.xml Code:
clock.xml
Figure 3 tab navigation using actionbar
Create an actionbar to implement tab navigation steps:
1. Call the setnavigationmode (actionbar. Navigation_mode_tabs) method of actionbar to use the tab navigation method
2. Call the add () method of actionbar to add multiple tab tags, and add event listeners for each tab tag
Mainactivity Code:
Dummyfragment.java Code:
A simple fragment that displays only one textview component
Figure 4 Fragment support before Android 3.0
The fragment before Android 3.0 does not inherit from app.fragment, but from v4.app.fragment. In addition, v4.app.fragment also provides the following supporting classes:
1.FragmentActivity 2.ViewPager 3.FragmentPagerAdapter 4.PagerTitleStrip
Main.xml Code:
Mainactivity Code:
Figure 5 implementation of drop-down navigation using actionbar
Create actionbar to implement drop-down navigation steps
1: Call the actionbar.setnavigationmode (actionbar. Navigation_mode_list) method of actionbar to set the navigation mode of the drop-down list
2: Call the setlistnavigationcallbacks (spinneradapter, actionbar. Onnavigationlistener callback) method of actionbar to add multiple list items and set listening events for each list item.
Mainactivity code area:
The use of actionbar in Android is basically here, and it will be updated in time in case of problems in future projects. If you have any questions, please leave a message.
Thank you for reading, hope to help you, thank you for your support to this site!