How to change icon colors in android studio

后端 未结 5 911
一个人的身影
一个人的身影 2021-02-05 04:32

I downloaded some icons from material.io but they only offer the icons in black. I saw a youtube video where they use to allow you to choose the color. Anyway, I am trying to

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-05 05:01

    As mentioned before, the material.io icons can be downloaded directly with Android Studio. This solution shows the importing of vector asset icons which are easier to manage since they are stored in a single location (res/drawable) vs. image assets that will have each icon stored in specific density folders (hdpi, xhdpi, etc).

    1. expand the "res" folder
    2. right click drawable
    3. hover over "new"
    4. select "Vector Asset"

    1. click the image next to "icon"
    2. select desired material.io icon
    3. Name the icon what you would like
    4. select "next"

    Now you will have two options of setting the icon color

    1. In the layout by using the android:tint attribute of an ImageView. This is my preference because the icon can be viewed prior to runtime.

    or

    1. In Java.

    imageView.setColorFilter(ContextCompat.getColor(context, android.R.color.white), PorterDuff.Mode.MULTIPLY);

提交回复
热议问题