改变材料图标的颜色?

时间:2017-01-05 19:06:01

标签: android android-layout android-studio

我从这里下载了许多素材图标:

https://material.io/icons/

我对如何将这些图标的颜色更改为可绘制内容感到困惑。我有一个ButtondrawableLeft属性中有一个图标,然后是一些带有图标的ImageButton,如下所示:

<Button
    android:text="Hey"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/ic_arrow_upward_black_24dp"
    android:stateListAnimator="@null" />

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/ic_arrow_downward_black_24dp"
    android:background="@null" />

如何更改每个图标的颜色?

此外,如果我下载的图标是黑色的,我如何将图标的颜色更改为透明的颜色?

5 个答案:

答案 0 :(得分:31)

您确实意识到https://material.io/icons/上的所有素材图标现已在 Android工作室中提供,无需甚至可以下载它们。只需右键点击 drawables&gt;新&gt;矢量资产

你会得到一个像

这样的对话框

this

点击 Android图标后,选择您的图片并保存。这将创建一个 xml drawable ,可以根据自己的喜好打开和编辑

以下是它的样子

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:alpha="0.8" <!--set the transparency from here -->
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FF000000" <!-- Use this for setting your color -->
        android:pathData="M9.4,16.6L4.8,12l4.6,-4.6L8,6l-6,6 6,6 1.4,-1.4zM14.6,16.6l4.6,-4.6 -4.6,-4.6L16,6l6,6 -6,6 -1.4,-1.4z"/>
</vector>

答案 1 :(得分:5)

将其添加到xml布局文件中的ImageButton

android:tint="@color/black"
android:tintMode="@color/black"

答案 2 :(得分:1)

所有appcompat小部件都支持1 print "hello" # skiping line number for commented line 2 print "line number for next line" 3 print "now the next line number" # again skipping another line that's commented with hash symbol 4 print "I hope you got what I meant!" 属性。如果您的活动/片段延伸android:tint="@color/somecolorresource",则适用于任何AppCompatActivity/Fragment

请参阅:https://stackoverflow.com/a/37261384/3662251

答案 3 :(得分:1)

如果您的图标是矢量,则可以编辑xml文件并更改android:fillColor属性。如果图标是位图,则可以将android:tint属性添加到ImageButton。

答案 4 :(得分:0)

link非常适合编辑图标,您也可以生成具有透明背景的图标。希望这有帮助。

相关问题