VectorDrawable has been introduced in Android Lollipop
release for one year.
We are getting many feedbacks that a good tool is needed
for the developers to create assets for VectorDrawable
and use them for older Android versions.
Hi, this is Tenghui from Android UI Toolkit team.
I'm happy to give you an update on our latest tool support
to adjust those concerns.
In Android Studio 1.4, we introduce a new tool for you
to either easily pick one vector asset from material design icon
library or convert your own SVG files into your vector
drawables.
Moreover, you can use this vector asset even
when you are building against pre-Lollipop release
without any code change.
That is very cool, right?
First, let's dive into the new UI
we introduced in Android Studio 1.4.
If you right click on any photos in your application,
you will see one menu options call New.
Click that.
You will see one sub-menu called Vector Asset.
Click that.
You will be able to see this new Vector Asset Studio dialogue.
Assuming right now, you just want
to pick one existing vector asset from material design icon
library, then you just click this Choose button.
Then, you would see a dialogue with all the asset
in the library.
Now, simply just pick one you like, then hit OK.
Now, you would see a nice preview for this vector asset.
If you are happy with how it looks,
then just go ahead and hit Next button.
Otherwise, there are some options
on the top right off this dialogue.
For example, you can change its width and height,
and you can modify the translucency
of the whole asset, or add auto-mirroring support
for right to left language.
Note that auto-mirroring support is only for version 21
and above.
In some other cases, if I just want to use your own SVG files,
then please click this radio button set, Local SVG File.
Then you would be able to open a file browser,
pick your own SVG files, then you
will be able to see the preview showing up.
Given SVG is a huge spec and often contains
many redundant information, although we
will continue to improve our tool to support more SVG files,
currently, we don't support all of the features in our tool
yet.
If we find anything in your SVG file that we don't support,
we will be report it as an error at the bottom.
Please look into the details of the error message
and simplify your SVG files and try to import again.
Or, if you're happy with the generated preview,
then feel free to go to the next page.
You will see an SML file with a preview showing up
in your res slash drawable directory,
and you only need to check in this simple SML file
into your [INAUDIBLE].
Hit the Finish button now.
Then the vector asset will be successfully generated for you.
Now, I will describe how the backward compatibility works
and its current limitation.
First of all, if your app is targeted
for Lollipop or newer versions, then the full API spec
is supported.
Feel free to modify and use the vector drawable
according to the spec.
However, we know many of you are developing on older platforms.
In order to support older platforms which
don't have VectorDrawable, we have some limitations
I will mention later.
Our [INAUDIBLE] system would generate a PNG asset
automatically for you.
Here's how this automatically generated assets looks like.
After you build an app, if you switch to the Project View,
you would notice there's a directory called PNGs
under the generated directory.
Under this PNGs directory, you will
see familiar drawable directories with different APIs
and version numbers.
In simple cases, you will see a pair of directory
for one particular DPI, like here-- one xxxhdpi directory
containing the PNG file and correspondingly
a xxxhdpi version 21 directory which
contains a copy of the vector drawable's SML file.
This file structure enables the build system
to pick up the vector drawable for SDK version 21 and above
while falling back to PNG files for older versions.
There are some limitations where we
are dealing with this backward compatibility support.
We are trying our best to show the link
errors in the vector drawable's SML file for these limitations.
First, only a subset of API features of VectorDrawable
are supported.
We are enhancing this now, but currently, group and click path
text are not supported, given we can only have one static PNG
file generated to replace VectorDrawable in older Android
version.
That also means in the SML file of VectorDrawable,
we cannot support dynamic attributes such as theming
or auto-mirroring.
And for performance concerns, we don't support resources
reference to other SML files.
Second, currently, the preview window inside Andriod Studio
is using a display engine which is different from the one used
in the Vector Asset Studio dialogue and the build process.
While we are bridging the gap between these two engines,
a good practice is to use Vector Asset
Studio to import your asset and keep the imported result.
Then, the generated PNGs will be always the same
as you see doing the import process.
Last, if you have to type cast the drawable object
in your Java code, be aware that on pre-Lollipop devices,
this drawable should be cast as BitmapDrawable
instead of a VectorDrawable.
Also, set the drawable's size properly
to make sure they show up correctly
in the older versions.
With all this tools update, I want
to thank all the people who helped
to get this tool delivered.
And I hope you find this as easier and more
pleasant to use VectorDrawable in your application.
Please follow us on more updates and improvements
in the near future.
Thank you.
[MUSIC PLAYING]