diff --git a/docs/html/tools/help/vector-asset-studio.jd b/docs/html/tools/help/vector-asset-studio.jd index 491a699265c7a..46adb99a97b7f 100644 --- a/docs/html/tools/help/vector-asset-studio.jd +++ b/docs/html/tools/help/vector-asset-studio.jd @@ -21,9 +21,10 @@ page.tags=vector

See also

  1. Create Vector Drawables
  2. -
  3. Material Icons
  4. +
  5. Material Icons
  6. Drawable Class
  7. VectorDrawable Class
  8. +
  9. Android Support Library 23.2

Videos

@@ -49,21 +50,33 @@ screen sizes and resolutions because you can display one vector drawable on all

About Vector Asset Studio

Vector Asset Studio adds a vector graphic to the project as an XML file that describes the image. -Maintaining one XML file can be easier than updating multiple raster graphics at various resolutions.

+Maintaining one XML file can be easier than updating multiple raster graphics at various +resolutions.

+ +

Android 4.4 (API level 20) and lower doesn't support vector drawables. If +your minimum API level is set at one of these API levels, you have two options +when using Vector Asset Studio: +generate Portable Network Graphic (PNG) files (the default) or use the Support +Library.

+ +

For backward-compatibility, Vector Asset Studio generates +raster images of the vector drawable. You can refer to vector assets as +{@link android.graphics.drawable.Drawable} in Java code or +@drawable in XML code; when your app runs, the corresponding vector +or raster image displays automatically depending on the API level.

+ +

To instead use Android Support Library 23.2 or higher, you must add +some statements to your build.gradle file. This technique uses +vector drawables only.

-

Android 4.4 (API level 20) and lower doesn't support vector drawables. If your minimum API level -is set at one of these API levels, Vector Asset Studio also directs Gradle to generate raster images -of the vector drawable for backward-compatibility. You can refer to vector assets as -{@link android.graphics.drawable.Drawable} in Java code or @drawable in XML code; when -your app runs, the corresponding vector or raster image displays automatically depending on the API -level.

Supported vector graphic types

The Google material design specification provides material icons that you can use in your Android apps. Vector -Asset Studio helps you choose, import, and size material icons, as well as define opacity and the +Asset Studio helps you choose, import, and size material icons, as well as +define opacity and the Right-to-Left (RTL) mirroring setting.

Vector Asset Studio also helps you to import your own SVG files. SVG is an XML-based open @@ -73,6 +86,11 @@ feedback about whether the graphics code is supported or not. If the SVG code is converts the file into an XML file containing {@link android.graphics.drawable.VectorDrawable} code.

+

For Android 5.0 (API level 21) and higher, you can use the {@link +android.graphics.drawable.AnimatedVectorDrawable} class to animate the properties of {@link +android.graphics.drawable.VectorDrawable}. For more information, see +Animating Vector Drawables.

+

Considerations for SVG files

A vector drawable is appropriate for simple icons. The @@ -93,9 +111,47 @@ isn't black, the icon color might instead blend with the tint color.

Vector drawable support at different API levels

+

The following table summarizes the two techniques you can use for +backward-compatibility with Android 4.4 (API level 20) and lower:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TechniqueGraphics TypeVectorDrawable XML ElementsAndroid Plugin for GradleBuild FlagsApp Code
PNG generationVector and PNGSubset supported1.5.0 or higherDefaultVariety of coding techniques supported
Support Library 23.2 or higherVectorFull support2.0 or higherSupport Library statements requiredSubset of coding techniques supported
+ +

Using vector graphics can produce a smaller APK, but the initial loading +of vector graphics can take longer.

+ +

PNG generation for backward-compatibility

+

Android 5.0 (API level 21) and higher provides vector drawable support. If your app has a minimum API level that is lower, Vector Asset Studio adds the vector drawable file to your -project; also, at build time, Gradle creates Portable Network Graphic (PNG) raster images at various +project; also, at build time, Gradle creates PNG raster images at various resolutions. Gradle generates the PNG densities specified by the Domain Specific Language (DSL) generatedDensities property in a build.gradle file. To generate PNGs, the build system requires Android @@ -163,14 +219,33 @@ Changing the values in the code should not cause any issues, as long as they’r you want to add XML elements, you need to make sure that they’re supported based on your minimum API level.

-

For Android 5.0 (API level 21) and higher, you can use the {@link -android.graphics.drawable.AnimatedVectorDrawable} class to animate the properties of {@link -android.graphics.drawable.VectorDrawable}. For more information, see -Animating Vector Drawables.

+

Support Library for backward-compatibility

+ +

This technique requires Android Support Library 23.2 or higher and Android +Plugin for Gradle 2.0 or higher, and uses vector drawables only. Before using +Vector Asset Studio, you must add a statement to your +build.gradle file:

+ +
+android {
+  defaultConfig {
+    vectorDrawables.useSupportLibrary = true
+  }
+}
+
+dependencies {
+  compile 'com.android.support:appcompat-v7:23.2.0'
+}
+ 
+ +

You must also use coding techniques that are compatible with the Support + Library. For more information, see + Android Support Library 23.2.

Running Vector Asset Studio

-

Follow these steps to start Vector Asset Studio:

+

To start Vector Asset Studio:

  1. In Android Studio, open an Android app project.
  2. @@ -208,7 +283,8 @@ android.graphics.drawable.VectorDrawable}. For more information, see

    Adding a material icon

    -

    After you open Vector Asset Studio, you can add a material icon as follows:

    +

    After you open Vector Asset Studio, you can add a material icon as +follows:

    1. In Vector Asset Studio, select Material Icon.
    2. @@ -235,7 +311,7 @@ android.graphics.drawable.VectorDrawable}. For more information, see display a mirror image of it in this case. Note that if you’re working with an older project, you might also need to add android:supportsRtl="true" to your app manifest. Auto-mirroring is - supported on Android 5.0 (API level 21) and higher only. + supported on Android 5.0 (API level 21) and higher, and the Support Library.
    3. Click Next.
    4. Optionally change the module and resource directory:
    5. @@ -244,13 +320,15 @@ android.graphics.drawable.VectorDrawable}. For more information, see resource. For more information, see Creating an Android Module.
    6. Res Directory - Select the resource source set where you want to add the - vector asset: src/main/res, src/debug/res, src/release/res, + vector asset: src/main/res, src/debug/res, + src/release/res, or a user-defined source set. The main source set applies to all build variants, including debug and release. The debug and release source sets override the main source set and apply to one version of a build. The debug source set is for debugging only. To define a new source set, select File > Project Structure > app > Build Types. For example, you could define a beta source set and create a - version of an icon that includes the text "BETA” in the bottom right corner. For more information, see + version of an icon that includes the text "BETA” in the bottom right corner. + For more information, see Working with Build Variants.
    7. The Output Directories area displays the vector image and the directory @@ -258,21 +336,26 @@ android.graphics.drawable.VectorDrawable}. For more information, see

    8. Click Finish.
    9. Vector Asset Studio adds an XML file defining the vector drawable to the project in the app/src/main/res/drawable/ folder. From the - Android view of the Project + Android view of the + Project window, you can view the generated vector XML file in the drawable folder.

    10. Build the project.
    11. -

      If the minimum API level is Android 4.4 (API level 20) and lower, Vector Asset Studio generates - PNG files. From the Project view +

      If the minimum API level is Android 4.4 (API level 20) and lower, and you + haven't enabled the Support Library technique, Vector Asset Studio generates + PNG files. From the + Project view of the Project window, you can view the generated PNG and XML files in the app/build/generated/res/pngs/debug/ folder.

      -

      You should not edit these generated raster files, but instead work with the vector XML file. The +

      You should not edit these generated raster files, but instead work with the vector XML file. + The build system regenerates the raster files automatically when needed so you don’t need to maintain them.

    Importing a Scalable Vector Graphic (SVG)

    -

    After you open Vector Asset Studio, you can import an SVG file as follows:

    +

    After you open Vector Asset Studio, you can import an SVG file as +follows:

    1. In Vector Asset Studio, select Local SVG file.
    2. @@ -286,7 +369,8 @@ android.graphics.drawable.VectorDrawable}. For more information, see

      In this case, you can’t use Vector Asset Studio to add the graphics file. Click More to view the errors. For a list of supported elements, see Vector Drawable Support at Different API Levels.

      -
    3. Optionally change the resource name, size, opacity, and Right-To-Left (RTL) mirroring setting:
    4. +
    5. Optionally change the resource name, size, opacity, and Right-To-Left (RTL) mirroring + setting:
    6. Click Next.
    7. Optionally change the module and resource directory:
    8. @@ -321,7 +405,8 @@ android.graphics.drawable.VectorDrawable}. For more information, see to one version of a build. The debug source set is for debugging only. To define a new source set, select File > Project Structure > app > Build Types. For example, you could define a beta source set and create a - version of an icon that includes the text "BETA” in the bottom right corner. For more information, see + version of an icon that includes the text "BETA” in the bottom right corner. + For more information, see Working with Build Variants.

      The Output Directories area displays the vector image and the directory @@ -329,14 +414,18 @@ android.graphics.drawable.VectorDrawable}. For more information, see

    9. Click Finish.
    10. Vector Asset Studio adds an XML file defining the vector drawable to the project in the app/src/main/res/drawable/ folder. From the - Android view of the Project + Android view of the + Project window, you can view the generated vector XML file in the drawable folder.

    11. Build the project.
    12. -

      If the minimum API level is Android 4.4 (API level 20) and lower, Vector Asset Studio generates - PNG files. From the Project view +

      If the minimum API level is Android 4.4 (API level 20) and lower, and you + haven't enabled the Support Library technique, Vector Asset Studio generates + PNG files. From the + Project view of the Project window, you can view the generated PNG and XML files in the app/build/generated/res/pngs/debug/ folder.

      -

      You should not edit these generated raster files, but instead work with the vector XML file. The +

      You should not edit these generated raster files, but instead work with the vector XML file. + The build system regenerates the raster files automatically when needed so you don’t need to maintain them.

    @@ -349,12 +438,13 @@ layout shows a vector asset displayed on a button:

    -

    Follow these steps to display a vector asset on a widget, as shown in the figure:

    +

    To display a vector asset on a widget, as shown in the figure:

    1. Open a project and import a vector asset.
    2. In the Android view of - the Project window, double-click a layout XML file, such as content_main.xml.
    3. + the Project window, double-click a layout XML file, such as + content_main.xml.
    4. Click the Design tab to display the Layout Editor.
    5. Drag the {@link @@ -365,13 +455,16 @@ android.widget.ImageButton} widget from the Palette window onto the Lay Drawable folder, and select a vector asset. Click OK.
    6. The vector asset appears on the ImageButton in the layout.

    7. To change the color of the image to the accent color defined in the theme, locate the - tint property in the Properties window and click … .
    8. + tint property in the Properties window and click … . +
    9. In the Resources dialog, select the Project tab, navigate to the - Color folder, and select colorAccent. Click OK.
    10. + Color folder, and select colorAccent. Click OK. +

      The color of the image changes to the accent color in the layout.

    -

    The ImageButton code should be similar to the following:

    +

    If you're not using the Support Library technique, the +ImageButton code should be similar to the following:

     <ImageButton
    @@ -417,17 +510,25 @@ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
     
    +

    For the Support Library technique, you must use coding techniques that are +compatible with the Support Library. For more information, see + Android Support Library 23.2.

    +

    Modifying XML Code Generated by Vector Asset Studio

    You can modify the vector asset XML code, but not the PNGs and corresponding XML code generated -at build time. However, we don't recommended it. Vector Asset Studio makes sure that the vector +at build time. However, we don't recommended it.

    + +

    When using the PNG generation technique, Vector Asset Studio makes sure that the vector drawable and the PNGs match, and that the manifest contains the proper code. If you add code that's not supported on Android 4.4 (API level 20) and lower, your vector and PNG images might differ. You also need to make sure that the manifest contains the code to support your changes.

    -

    Follow these steps to modify the vector XML file:

    +

    To modify the vector XML file when you're not using the Support Library +technique:

    1. In the Project window, double-click the generated vector XML file in the @@ -450,7 +551,8 @@ changes.

      supported.
    2. For example, if you didn’t select the RTL option in Vector Asset Studio but realize you now - need it, you can add the autoMirrored + need it, you can add the + autoMirrored attribute later. To view the RTL version, select Preview Right-to-Left Layout in the menu of the Preview window. (Select None to remove the RTL preview.)

      @@ -466,7 +568,8 @@ changes.

      unsupported in Android 4.4 (API level 20) and lower don't appear in the generated PNG files. As a result, when you add code, you should always check that the generated PNGs match the vector drawable. To do so, you could double-click the PNG in the - Project view of the Project + Project view of the + Project window; the left margin of the code editor also displays the PNG image when your code refers to the drawable.

      @@ -475,11 +578,12 @@ changes.

      Deleting a Vector Asset from a Project

      -

      Follow these steps to remove a vector asset from a project:

      +

      To remove a vector asset from a project:

      1. In the Project window, delete the generated vector XML file by selecting the file and - pressing the Delete key (or select Edit > Delete).
      2. + pressing the Delete key (or select Edit > + Delete).

        The Safe Delete dialog appears.

      3. Optionally select options to find where the file is used in the project, and click OK.
      4. @@ -493,14 +597,23 @@ changes.

        Delivering an App Containing Vector Drawables

        -

        When your minimum API level includes Android 4.4 (API level 20) or lower, you have corresponding - vector and raster images in your project. In this case, you have two options for delivering your - APK files:

        +

        If you used the Support Library technique or your minimum API level is +Android 5.0 (API level 21) or higher, your APK will contain the vector images +that you added with Vector Asset Studio. +These APKs will be smaller than if the vector images were converted to PNGs. +

        + + +

        When your minimum API level includes Android 4.4 (API level 20) or lower, + and you have corresponding vector and raster images in your project, + you have two options for delivering your APK files:

          -
        • Create one APK that includes both the vector images and the corresponding raster - representations. This solution is the simplest to implement.
        • -
        • Create separate APKs for different API levels. When you don’t include the corresponding - raster images in the APK for Android 5.0 (API level 21) and higher, the APK can be much smaller in - size. For more information, see Multiple APK Support.
        • +
        • Create one APK that includes both the vector images and the corresponding + raster representations. This solution is the simplest to implement.
        • +
        • Create separate APKs for different API levels. When you don’t include the + corresponding raster images in the APK for Android 5.0 (API level 21) and + higher, the APK can be much smaller in size. For more information, see + Multiple APK Support. +