1 page.title=Action Bar 2 @jd:body 3 4 <img src="{@docRoot}design/media/action_bar_pattern_overview.png"> 5 6 <p>The <em>action bar</em> is arguably the most important structural element of an Android app. It's a 7 dedicated piece of real estate at the top of each screen that is generally persistent throughout the 8 app.</p> 9 <p><strong>The main purpose of the action bar is to</strong>:</p> 10 <ul> 11 <li>Make important actions (such as <em>New</em> or <em>Search</em>, etc) prominent and accessible in a predictable 12 way.</li> 13 <li>Support consistent navigation and view switching within apps.</li> 14 <li>Reduce clutter by providing an action overflow for rarely used actions.</li> 15 <li>Provide a dedicated space for giving your app an identity.</li> 16 </ul> 17 <p>If you're new to writing Android apps, note that the action bar is one of the most important design 18 elements you can implement. Following the guidelines described here will go a long way toward making 19 your app's interface consistent with the core Android apps.</p> 20 <h2 id="organization">General Organization</h2> 21 22 <p>The action bar is split into four different functional areas that apply to most apps.</p> 23 <img src="{@docRoot}design/media/action_bar_basics.png"> 24 25 <div class="layout-content-row"> 26 <div class="layout-content-col span-7 with-callouts"> 27 28 <ol> 29 <li class="value-1"><h4>App icon</h4> 30 <p> 31 32 The app icon establishes your app's identity. It can be replaced with a different logo or branding 33 if you wish. 34 Important: If the app is currently not displaying the top-level screen, be sure to display the Up 35 caret to the left of the app icon, so the user can navigate up the hierarchy. For more discussion of 36 Up navigation, see the <a href="{@docRoot}design/patterns/navigation.html">Navigation</a> pattern. 37 38 <div class="figure"> 39 <img src="{@docRoot}design/media/action_bar_pattern_up_app_icon.png"> 40 <div class="figure-caption"> 41 App icon with and without "up" affordance. 42 </div> 43 </div> 44 45 </p> 46 </li> 47 </ol> 48 49 </div> 50 <div class="layout-content-col span-6 with-callouts"> 51 52 <ol> 53 <li class="value-2"><h4>View control</h4> 54 <p> 55 56 If your app displays data in different views, this segment of the action bar allows users to switch 57 views. Examples of view-switching controls are drop-down menus or tab controls. 58 59 </p> 60 <p> 61 62 If your app doesn't support different views, you can also use this space to display non-interactive 63 content, such as an app title or longer branding information. 64 65 </p> 66 </li> 67 <li class="value-3"><h4>Action buttons</h4> 68 <p> 69 70 Show the most important actions of your app in the actions section. Actions that don't fit in the 71 action bar are moved automatically to the action overflow. 72 73 </p> 74 </li> 75 <li class="value-4"><h4>Action overflow</h4> 76 <p> 77 78 Move less often used actions to the action overflow. 79 80 </p> 81 </li> 82 </ol> 83 </div> 84 </div> 85 86 <h2 id="adapting-rotation">Adapting to Rotation and Different Screen Sizes</h2> 87 88 <p>One of the most important UI issues to consider when creating an app is how to adjust to screen 89 rotation on different screen sizes.</p> 90 <p>You can adapt to such changes by using <em>split action bars</em>, which allow you to distribute action bar 91 content across multiple bars located below the main action bar or at the bottom of the screen.</p> 92 93 <img src="{@docRoot}design/media/action_bar_pattern_rotation.png"> 94 <div class="figure-caption"> 95 Split action bar showing action buttons at the bottom of the screen in vertical orientation. 96 </div> 97 98 <h2 id="considerations-split-action-bars">Layout Considerations for Split Action Bars</h2> 99 100 <div class="layout-content-row"> 101 <div class="layout-content-col span-8 with-callouts"> 102 103 <p>When splitting up content across multiple action bars, you generally have three possible locations 104 for action bar content:</p> 105 <ol> 106 <li><strong>Main action bar</strong></li> 107 <li><strong>Top bar</strong></li> 108 <li><strong>Bottom bar</strong></li> 109 </ol> 110 <p>If the user can navigate up the hierarchy from a given screen, the main action bar contains the up 111 caret, at a minimum.</p> 112 <p>To allow the user to quickly switch between the views your app provides, use tabs or a spinner in 113 the top bar.</p> 114 <p>To display actions and, if necessary, the action overflow, use the bottom bar.</p> 115 116 </div> 117 <div class="layout-content-col span-3"> 118 119 <img src="{@docRoot}design/media/action_bar_pattern_considerations.png"> 120 121 </div> 122 </div> 123 124 <h2 id="contextual">Contextual Action Bars</h2> 125 126 <p>A <em>contextual action bar (CAB)</em> is a temporary action bar that overlays the app's action bar for the 127 duration of a particular sub-task. CABs are most typically used for tasks that involve acting on 128 selected data or text.</p> 129 130 <img src="{@docRoot}design/media/action_bar_cab.png"> 131 <div class="figure-caption"> 132 Contextual action bar shown in Browser and Gmail 133 </div> 134 135 <p>The selection CAB appears after a long press on a selectable data item triggers selection mode.</p> 136 <p><strong>From here the user can</strong>:</p> 137 <ul> 138 <li>Select additional elements by touching them.</li> 139 <li>Trigger an action from the CAB that applies to all selected data items. The CAB then 140 automatically dismisses itself.</li> 141 <li>Dismiss the CAB via the navigation bar's Back button or the CAB's checkmark button. This removes 142 the CAB along with all selection highlights.</li> 143 </ul> 144 <p>Use CABs whenever you allow the user to select data via long press. You can control the action 145 content of a CAB in order to insert the actions you would like the user to be able to perform.</p> 146 <p>For more information, refer to the "Selection" pattern.</p> 147 <h2 id="elements">Action Bar Elements</h2> 148 149 <h4>Tabs</h4> 150 <p><em>Tabs</em> display app views concurrently and make it easy to explore and switch between them. Use tabs 151 if you expect your users to switch views frequently.</p> 152 153 <img src="{@docRoot}design/media/tabs_youtube.png"> 154 155 <p>There are two types of tabs: fixed and scrollable.</p> 156 157 <div class="layout-content-row"> 158 <div class="layout-content-col span-6"> 159 160 <h4>Scrollable tabs</h4> 161 <p><em>Scrollable tabs</em> always take up the entire width of the bar, with the currently active view item in 162 the center, and therefore need to live in a dedicated bar. Scrollable tabs can themselves be 163 scrolled horizontally to bring more tabs into view.</p> 164 <p>Use scrollable tabs if you have a large number of views or if you're unsure how many views will be 165 displayed because your app inserts views dynamically (for example, open chats in a messaging app 166 that the user can navigate between). Scrollable tabs should always allow the user to navigate 167 between the views by swiping left or right on the content area as well as swiping the tabs 168 themselves.</p> 169 170 </div> 171 <div class="layout-content-col span-7"> 172 173 <video width="400" class="with-shadow play-on-hover" autoplay> 174 <source src="{@docRoot}design/media/tabs_scrolly.mp4" type="video/mp4"> 175 <source src="{@docRoot}design/media/tabs_scrolly.webm" type="video/webm"> 176 <source src="{@docRoot}design/media/tabs_scrolly.ogv" type="video/ogg"> 177 </video> 178 <div class="figure-caption"> 179 Scrolling tabs in Google Play. 180 <div class="video-instructions"> </div> 181 </div> 182 183 </div> 184 </div> 185 186 <div class="layout-content-row"> 187 <div class="layout-content-col span-6"> 188 189 <h4>Fixed tabs</h4> 190 <p><em>Fixed tabs</em> are always visible on the screen, and can't be moved out of the way like scrollable 191 tabs. Fixed tabs in the main action bar can move to the top bar when the screen orientation changes.</p> 192 193 </div> 194 <div class="layout-content-col span-7"> 195 196 <img src="{@docRoot}design/media/action_bar_pattern_default_tabs.png"> 197 <div class="figure-caption"> 198 Default fixed tabs shown in Holo Dark & Light. 199 </div> 200 201 </div> 202 </div> 203 204 <div class="layout-content-row"> 205 <div class="layout-content-col span-6"> 206 207 <h4>Spinners</h4> 208 <p>A <em>spinner</em> is a drop-down menu that allows users to switch between views of your app. </p> 209 <p><strong>Use spinners rather than tabs in the main action bar if</strong>:</p> 210 <ul> 211 <li>You don't want to give up the vertical screen real estate for a dedicated tab bar.</li> 212 <li>You expect your app's users to switch views infrequently.</li> 213 </ul> 214 215 </div> 216 <div class="layout-content-col span-7"> 217 218 <img src="{@docRoot}design/media/action_bar_pattern_spinner.png"> 219 <div class="figure-caption"> 220 Action bar spinner from Calendar application. 221 </div> 222 223 </div> 224 </div> 225 226 <h4>Action buttons</h4> 227 <p><em>Action buttons</em> on the action bar surface your app's most important activities. Think about which 228 buttons will get used most often, and order them accordingly. Depending on available screen real 229 estate, the system shows your most important actions as action buttons and moves the rest to the 230 action overflow. The action bar and the action overflow should only present actions to the user that 231 are available. If an action is unavailable in the current context, hide it. Do not show it as 232 disabled.</p> 233 234 <img src="{@docRoot}design/media/action_bar_pattern_action_icons.png"> 235 <div class="figure-caption"> 236 A sampling of action buttons used throughout the Gmail application. 237 </div> 238 239 <p>For guidance on prioritizing actions, use the FIT scheme.</p> 240 241 <div class="layout-content-row"> 242 <div class="layout-content-col span-4"> 243 244 <p><strong>F — Frequent</strong></p> 245 <ul> 246 <li>Will people use this action at least 7 out of 10 times they visit the screen?</li> 247 <li>Will they typically use it several times in a row?</li> 248 <li>Would taking an extra step every time truly be burdensome?</li> 249 </ul> 250 251 </div> 252 <div class="layout-content-col span-4"> 253 254 <p><strong>I — Important</strong></p> 255 <ul> 256 <li>Do you want everyone to discover this action because it's especially cool or a selling point?</li> 257 <li>Is it something that needs to be effortless in the rare cases it's needed?</li> 258 </ul> 259 260 </div> 261 <div class="layout-content-col span-4"> 262 263 <p><strong>T — Typical</strong></p> 264 <ul> 265 <li>Is it typically presented as a first-class action in similar apps?</li> 266 <li>Given the context, would people be surprised if it were buried in the action overflow?</li> 267 </ul> 268 269 </div> 270 </div> 271 272 <p>If either F, I, or T apply, then it's appropriate for the action bar. Otherwise, it belongs in the 273 action overflow.</p> 274 275 <p> 276 277 Pre-defined glyphs should be used for certain common actions such as "refresh" and "share." The 278 download link below provides a package with icons that are scaled for various screen densities and 279 are suitable for use with the Holo Light and Holo Dark themes. The package also includes unstyled 280 icons that you can modify to match your theme, in addition to Adobe® Illustrator® source 281 files for further customization. 282 283 </p> 284 <p> 285 286 <a href="https://dl-ssl.google.com/android/design/Android_Design_Icons_20120229.zip">Download the Action Bar Icon Pack</a> 287 288 </p> 289 290 <div class="layout-content-row"> 291 <div class="layout-content-col span-6"> 292 293 <h4>Action overflow</h4> 294 <p>The action overflow in the action bar provides access to your app's less frequently used actions. 295 The overflow icon only appears on phones that have no menu hardware keys. Phones with menu keys 296 display the action overflow when the user presses the key.</p> 297 298 </div> 299 <div class="layout-content-col span-7"> 300 301 <img src="{@docRoot}design/media/action_bar_pattern_overflow.png"> 302 <div class="figure-caption"> 303 Action overflow is pinned to the right side. 304 </div> 305 306 </div> 307 </div> 308 309 <p>How many actions will fit in the main action bar? Action bar capacity is controlled by the following 310 rules:</p> 311 <ul> 312 <li>Action buttons in the main action bar may not occupy more than 50% of the bar's width. Action 313 buttons on bottom action bars can use the entire width.</li> 314 <li>The screen width in density-independent pixels 315 (<acronym title="Density-independent pixels. One dp is one pixel on a 160 dpi screen.">dp</acronym>) 316 determine the number of items that will fit in the main action bar:<ul> 317 <li>smaller than 360 dp = 2 icons</li> 318 <li>360-499 dp = 3 icons</li> 319 <li>500-599 dp = 4 icons</li> 320 <li>600 dp and larger = 5 icons</li> 321 </ul> 322 </li> 323 </ul> 324 325 <img src="{@docRoot}design/media/action_bar_pattern_table.png"> 326 <div class="figure-caption"> 327 In the above table "o" denotes an action bar item and "=" an overflow icon. 328 </div> 329 330 <h4>Sharing data</h4> 331 <p>Whenever your app permits sharing of data, such as images or movie clips, use a <em>share action 332 provider</em> in your action bar. The share action provider is designed to speed up sharing by 333 displaying the most recently used sharing service next to a spinner button that contains other 334 sharing options.</p> 335 336 <img src="{@docRoot}design/media/action_bar_pattern_share_pack.png"> 337 <div class="figure-caption"> 338 The Gallery app's share action provider with extended spinner for additional sharing options. 339 </div> 340 341 <h2 id="checklist">Action Bar Checklist</h2> 342 343 <p>When planning your split action bars, ask yourself questions like these:</p> 344 <h4>How important is view navigation to the task?</h4> 345 <p>If view navigation is very important to your app, use tabs (for fastest view-switching) or spinners.</p> 346 <h4>Which of the app's actions need to be consistently available directly from the action bar, and which can be moved to the action overflow?</h4> 347 <p>Use the <acronym title="Frequent, Important or Typical">FIT</acronym> scheme to decide if actions 348 are displayed at the top-level or can be moved to the action overflow. If the number of top-level 349 actions exceeds the capacity of the main action bar, display them separately in a bottom action bar.</p> 350 <h4>What else is important enough to warrant continuous display?</h4> 351 <p>Sometimes it is important to display contextual information for your app that's always visible. 352 Examples are the number of unread messages in a messaging inbox view or the Now Playing information 353 in a music player. Carefully plan which important information you would like to display and 354 structure your action bars accordingly.</p> 355