Android Support Library: Consistent Design with AppCompat

Android Support Library: Consistent Design with AppCompat


Android has changed
a lot over the years, from the classic Android
design, through Holo, and now material design. How do you build an app that
looks great and consistent across all these devices
and Android versions? That’s where AppCompat comes in,
giving you a consistent theme and baseline for
your applications that stays in sync with the
latest version of Android. Hi, I’m Ian Lake. I’m here to tell you about
the features of AppCompat, how to get started, and why
it’s one of the keys to building apps faster. So how exactly do you
transform our default state into something great? In fact, there’s only
two changes needed. The first part is
the AppCompat theme. It encapsulates all of the
version specific logic for you, giving you just a
single theme to use. The second part is the
switch to AppCompat activity, and this is what gives
us a consistent action bar, contextual action modes,
and support for toolbars, as well as the features of
its parent class, fragment activity, including
fragments and loaders. And just like that, we have
a single, consistent look and feel that works on
over a billion devices. Not bad. But the default theme is
only a starting point. AppCompat brings the material
color palette to all devices, making it easy to
bring your brand’s color into every
part of your app with a single, simple theme. Let’s create a theme and
set the three main colors. Color primary, which
controls the action bar coloring, and should be
your main branding color. Color primary dark,
which is a darker variant of your primary
color, and used to color the status bar on
platforms that support it. And color accent, which actually
provides the accent coloring for views, such as checkboxes,
edit text, and radio buttons. So how does our coloring look? Pretty good. You’ll notice that
all of our widgets now use our custom coloring. You’ll also get backward
compatible versions of alert dialogue, search
view, share action provider, contextual action
modes, and toolbars, giving you a consistent set
of the latest and greatest components, so you don’t have
to compromise your design to support all of your users. So how do you get AppCompat into
your project in Android Studio? It’s easy. The templates for new
projects and new activities automatically include
AppCompat, giving you the basics by default. If you
have an existing project you want to switch over, you’ll
add a single dependency to your build.gradle
file, change your theme, move over to AppCompat activity,
and replace a few method calls with their support
library equivalents, hopefully removing a bunch
of version specific code in the process. With AppCompat giving
you a consistent base, you can focus on what
makes your app unique. We’ve touched on
just a few things that you get through AppCompat. You can learn more about
the Android support library and AppCompat
on the developer site.

Only registered users can comment.

  1. I still can't find support for PreferenceActivity/PreferenceFragment (missing ever since Honeycomb), and ProgressDialog too.
    And RecyclerView is probably still missing some good stuff existing on ListView (header/footer and fast-scroller, for example).

  2. I'm using "ActionBarActivity",because it alow me to use action bar in older devices, API 7+, should I change it to "AppCompatActivity"?

  3. your platform would be better than iOS in terms of coding if you focused on reducing boilerplate code, take a custom view for example, your android version of custom view sucks compared to the one that can be made by @IBDesignable, so much boilerplate code everywhere…This is one step towards it but you ll need several more

  4. Thank you for the explanation, but i have a problem, i am unable to see any of my icons in actionbar……..
    Can anyone help me?

  5. Just so you know, Google sample apps don't use AlertDialogs all the time, not even the app-compat ones. They theme new Activities into Dialogs so they are dismissable when clicking outside the non-parent-wrapping "Dialog" layout. They can thus create a "Card" looking Dialog, themed with Material, and way prettier than a Dialog.

  6. So, I don't get this, my Android Studio is updated to version 1.2 but the basic templates activities keep extending from ActionBarActivity. I know I can change the templates manually but would rather use a default template. Any idea how can I get Android Studio to use the latest templates?

  7. Yea, but I don't want my app to look like Material Design on Eclair, it should look like other Eclair apps, so as to be consistent along the entire device, and probably Eclair design is much less resource intensive, more appropriate for the old devices.

    If anything, this video has pushed me off AppCompat

  8. No offense Ian but this video is not helpful. Conclusion is: use AppCompat theme because it is great. Ok… I believe but if you could make this video 6 – 7 minutes instead of 2:40 and go more into details it would be really great. Especially that official Android documentation with list of features says only TWO sentences about v7 appcompat library.

  9. I really wish AppCompat was an automatic under the hood thing that not even developers had to mess with. Android has gotten so complex and obtuse that someone really needs to have a rethink about how it is done. Why can't we just sub class Actvity, set the min, max and target versions and let the framework figure it out compatibility for itself during compilation and install.

Leave a Reply

Your email address will not be published. Required fields are marked *