Langsung ke konten utama

Customizing the Action Bar

[This post is by Nick Butcher, an Android engineer who notices small imperfections, and they annoy him. — Tim Bray]

Since the introduction of the Action Bar design pattern, many applications have adopted it as a way to provide easy access to common actions. In Android 3.0 (or Honeycomb to its friends) this pattern has been baked in as the default navigation paradigm and extended to take advantage of the extra real-estate available on tablets. By using the Action Bar in your Honeycomb-targeted apps, you'll give your users a familiar way to interact with your application. Also, your app will be better prepared to scale across the range of Android devices that will be arriving starting in the Honeycomb era.

Just because Action Bars are familiar, doesn’t mean that they have to be identical! The following code samples and accompanying project demonstrate how to style the Action Bar to match your application’s branding. I’ll demonstrate how to take Honeycomb’s Holo.Light theme and customise it to match this blog’s colour scheme.

Icon

This step is easy; I’ll use the wonderful Android Asset Studio to create an icon in my chosen colour scheme. For extra credit, I’ll use this image as a starting point to create a more branded logo.

Navigation

Next up, the navigation section of the Action Bar operates in three different modes; I’ll tackle each of these in turn.

Standard

The Action Bar’s standard navigation mode simply displays the title of the activity. This doesn’t require any styling... next!

List

To the left, a standard list drop-down; to the right, the effect we want to achieve.

The default styling in list navigation mode has a blue colour scheme. This is evident when touching the collapsed control in both the top bar, and the selection highlight in the expanded list. We can theme this element by overriding android:actionDropDownStyle with a custom style to implement our colour scheme:

 

The above uses a combination of state list drawables and 9 patch images to style the collapsed spinner, the top bar of the expanded list and sets the highlight colour when picking an item.

Tabs

Here are the before-and-after shots on the tab navigation control:

The tab navigation control uses the standard blue colouring. We can apply a custom style to android:actionBarTabStyle to set our own custom drawable that uses our desired palette:

 

Actions

Before-and-after on the individual items in the Action Bar:

The individual action items inherit the default blue background when selected. We can customise this behaviour by overridingandroid:selectableItemBackground and setting a shape drawable with our desired colouring:

@drawable/ad_selectable_background

The overflow menu also needs some attention as when expanded it shows a blue bar at the top of the list. We can override android:popupMenuStyle and set a custom drawable (in fact the very same drawable we previously used for list navigation) for the top of the overflow menu:

 

Selecting items within the overflow menu also show the default selection colour. We can set our customised selection colour by overridingandroid:dropDownListViewStyle:

 

These changes gets us most of the way there but it’s attention to detail that makes an app. Check boxes and radio buttons within menu items in the overflow section are still using the default assets which have a blue highlight. Let’s override them to fit in with our theme:

@drawable/ad_btn_check_holo_light @drawable/ad_btn_radio_holo_light

Background

I’ve left the background transparent as inheriting form Holo.Light works well for our desired palette. If you’d like to customise it you easily override theandroid:background item on the android:actionBarStyle style:

Bringing it all together

Putting all of these components together we can create a custom style:

We can then apply this style to either an individual activity or to the entire application:

 

Note that some of the system styles that we have overridden in this example will affect much more than the Action Bar. For example overriding android:selectableItemBackground will effect many widgets which support a selectable state. This is useful for styling your entire application but be sure to test that your customisations are applied consistently throughout.

Familiar but styled

Customising the action bar is a great way to extend your application’s branding to the standard control components. With this power, as they say, comes great responsibility. When customising the user interface you must take great care to ensure that your application remains legible and navigable. In particular, watch out for highlight colours which contrast poorly with text and provide drawables for all relevant states. Explore this demo application which exercises the functionality offered by the Action Bar and demonstrates how to theme it.



Source android-developers

Komentar

Postingan populer dari blog ini

Lifehacker Pack for Android: Our List of the Best Android Apps

Whether you're an faithful Android user or you've just unboxed your first Android phone, there's a wealth of free and cheap apps in the Android Market that can turn your device into a mobile powerhouse. Our second annual Lifehacker Pack for Android is stuffed full of apps to keep you connected to home, office and friends, or just help you stay entertained on the go. The Lifehacker Pack is a yearly snapshot of our favorite, must-have applications for each of our favorite platforms. If you're curious to see how things have changed this year, here's last year's Lifehacker Pack for Android . Want to skip to a specific category? Use these links: Productivity Internet/Communication Location-Aware Utilities Media Food and Entertainment Art and Photography The Extended Pack Productivity Evernote Evernote for Android has been regularly updated and has come a long way since it made it into our pack last year. The app scored a huge update...

Motorola Devour specs: 3.1-inch screen, Android 1.6, MotorBLUR

Posted on Tuesday, Feb 2, 2010 by Phil Nickinson We brought you the promotional packaging for the Motorola Devour . But how would you like some specs? Here we go with the phone formerly known as the Calgary, which we're expecting on Verizon anytime now. (Yes, that's a Droid in the picture above. We're told that's just a placeholder.) The biggies: Android 1.6 ( Donut ) with MotoBLUR . A 3.1-inch touchscreen (320x480). 3MP camera. Verizon is requiring a data plan, and the $350 early termination fee is in effect. It comes with an 8GB microSD card. Still no word on price or when it will go on sale, but we're told it could be anytime now. There's a better breakdown and more screenies after the break. 3.1-inch touchscreen at 320x480. Dimensions: 4.55x2.4x0.61 inches. Weight: 6.35 ounces Talk time: Up to 340 minutes Standby time: Up to 440 hours Horizontal slider keyboard. 3-megapixel camera. EVDO Rev. A. WiFi b/g aGPS Audio formats: AAC, AAC+, ...

JOINTS 2010 -Lets Android The World- UGM 31 Mei 2010

Just share aja ma temen-temen di UGM tentang Android, smoga bermanfaat and jangan lupa gabung di Jogjadroid ya trus langsung Action. Himakom UGM