Search code examples
androidandroid-studiomaterial-components-androidmaterial-components

How to use "Material Components for Android" library


I'm building my first app on android and I'd like to use "Material Components for Android" library to have more design options.
I read the getting started page carfully but it seems that my app doesn't inherit correctly. ``error image saying that it cannot recognize some inherited data...
more expamples: cannot recognize label and the display is: display


Solution

  • In order to use the icons that Material Components for Android provide, you'll need to import them into your project first. To do so, you can click this link, but to fight off link rot, I've added the instructions below:

    To import icons from Vector Asset Studio:

    1. In Android Studio, open an Android app project.
    2. In the Project window, select the Android view. It should look like this: Screenshot of Android Studio in Android View
    3. Right-click the res folder and select New > Vector Asset

    Vector Asset Studio appears. Screenshot of Vector Asset Studio in Android Studio

    1. In Vector Asset Studio, select Material Icon.
    2. In the Icon field, click the button.
    3. The Select Icon dialog appears. You can filter which icons are visible by selecting an icon category from the list on the left or typing in the search field as shown here. Screenshot of Vector Asset Studio where the user can filter for material icons
    4. Select a material icon and click OK. The icon appears in the Vector Drawable Preview.
    5. Optionally change the resource name, size, opacity, and Right-To-Left mirroring setting. In your case, you'll want to make sure that the size is 24dp.
    6. Click Next.
    7. Optionally change the module and resource directory.
    8. Click Finish.
    9. Build the project.

    Now, you'll be able to import the selected icon.

    For the app:startIconContentDescription property, you'll have to add that yourself. The goal of the property is to make it easier for anyone using screen readers to understand the action of the text field (source).