Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
Android allows us to include support libraries in our code that make our apps work and look more consistently across both current and older versions of Android. We're making use of the AppCompat package from the support libraries in this project.
One of the things that's really helpful
about themes, is that we can use them to
0:00
make our app look pretty consistent across
many different versions of Android.
0:03
We used to have to do this using
multiple styles that targeted
0:07
different versions of the SDK.
0:10
But we get a lot of help now by way
of the Android support libraries.
0:12
Check out how this is described here,
in the Android developer docs.
0:16
You may want a standard way
to provide newer features on
0:19
earlier versions of Android, or gracefully
fall back to equivalent functionality.
0:22
Rather than building code to handle
earlier versions of the platform,
0:26
you can leverage these libraries to
provide that compatibility layer.
0:30
So what that's telling us is that,
we can plug in this support library to our
0:33
project, and there are some things
available for us that make it easy for
0:37
our app to be backwards compatible
on older versions of Android.
0:40
That's important because some of
those older versions don't have
0:44
some of the newer features
that we're using in our app.
0:46
So by default, we are taking advantage
of a few compatibility features
0:49
provided by the app components
package of the support library.
0:53
If we click on Features over here,
0:56
we can read about some of the common
useful components available to us.
0:59
For example,
1:03
this dark gray bar here at the top
of our screen is called the App Bar.
1:03
And it wasn't always a part of Android.
1:07
It was first introduced in
an older version of Android,
1:09
and it was called the Action Bar.
1:11
And then it was updated and
re-named to the App Bar.
1:12
So, some older versions of Android
that people are still using,
1:15
don't have an App Bar, or an Action Bar.
1:18
But, it's really useful for
1:20
certain actions and app navigation,
which we'll learn more about later.
1:21
But we can include the app bar
on older versions of Android,
1:25
by using the appcompat support library.
1:28
Let's take a look at what was
created automatically for us.
1:31
So first let's dig into
our build.gradle file,
1:34
remember to click on the second one here,
the Module app one.
1:36
And down here at the bottom we
see a dependency for appcompat.
1:39
So this first part, com.android.support
is how we include the support library.
1:45
Then different sections of
the support library like appcompat
1:51
are specified after the colon and then
the specific version is appended last.
1:54
So this was included automatically for
us but if you ever need to add
1:59
a new support library package yourself
you can look it up in the developer docs.
2:02
Let's go back and take a look.
2:06
Normally, I would just search for
the support library or
2:08
the specific package up here at the top.
2:10
But, we're already at the right page.
2:12
So, if we click on
Packages here on the left,
2:14
we now see all the available
packages in here on the right.
2:17
If we click on one, like v7 appcompat
library we can find the exact
2:20
value that we should use in our
Gradle file, here it is down here.
2:25
Note that this will always be the latest
version of the support library,
2:29
which you can update by using the STK
manager that we briefly explored earlier.
2:33
To do so
just come up here back to the STK manager.
2:37
Click on SDK Tools here and then make sure
that Android Support Library is checked
2:40
and that it's completely installed and
up to date.
2:45
Okay, so
this includes the appcompact package and
2:48
that means that we can
use its features in code.
2:51
Back in styles.xml,
2:54
we saw there were already extending
an AppCompat theme right here.
2:55
Next if we open up mainactivy.java
we see that it's extending
3:00
AppCompactActivity instead
of a regular activity class.
3:04
Again this is used to make sure
that the app bar works on older
3:08
versions of Android.
3:10
This AppCompactActivity provides an app
bar and also some material design
3:12
aesthetic changes which makes things
look more consistent across versions.
3:16
We'll explore some of the other support
library features in future projects
3:20
like a recycle view, but it's important
to know what the support library is and
3:23
how to include different packages.
3:27
Remember that its main function
is to make your app look and
3:29
work virtually the same on both old and
new versions of Android
3:31
You need to sign up for Treehouse in order to download course files.
Sign up