繁体   English   中英

图标颜色作为android工作室中的渐变

[英]Icon color as gradient in android studio

我希望我的图标有渐变 我找到了如何制作渐变背景,但在我的情况下它并没有帮助。

这是我的图标代码:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:strokeColor="#000"
        android:fillColor="#000"
        android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0"/>
    <path
        android:fillColor="#FF000000"
        android:pathData="M9,2L7.17,4L4,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2L9,2zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z"/>
</vector>

到目前为止,我做了这个以得到一个渐变文本:

mPicGallery = (Button) getView().findViewById(R.id.get_picture_gallery);
Shader textShader_8 = new LinearGradient(200, 20, 50, 10, new int[]{Color.parseColor("#01579b"),Color.parseColor("#006064")}, new float[]{0, 1}, Shader.TileMode.CLAMP);
mPicGallery.getPaint().setShader(textShader_8);

它很脏,但我找不到更好的方法。

所以我的问题是:如何使用渐变颜色制作图标。

我的意思是:

我的意思的例子

尝试在VectorDrawable中执行此操作,如下所示

<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">

<path
    android:fillType="evenOdd"
    android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0">
    <aapt:attr name="android:fillColor">
        <gradient
            android:gradientRadius="22"
            android:type="radial">
            <item
                android:color="#000000"
                android:offset="0.0" />
            <item
                android:color="#FFFFFFFF"
                android:offset="1.0" />
        </gradient>
    </aapt:attr>
</path>
<path
    android:fillColor="#FF000000"
    android:pathData="M9,2L7.17,4L4,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2L9,2zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z" />

您将在文档中找到更多详细信息

https://developer.android.com/reference/android/graphics/drawable/GradientDrawable

如果你问叔叔谷歌可能还有更多的教程:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM