Android 如何使用xml定义创建铅笔图标?

Android 如何使用xml定义创建铅笔图标?,android,xml,drawable,xml-drawable,Android,Xml,Drawable,Xml Drawable,我正在尝试使用线条(xml定义)创建铅笔图标。但没有得到确切的形状。是否可能?如果要使用Vector Drawable,请尝试使用下面的代码作为Drawable.xml <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24.0"

我正在尝试使用线条(xml定义)创建铅笔图标。但没有得到确切的形状。是否可能?

如果要使用Vector Drawable,请尝试使用下面的代码作为Drawable.xml

<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:fillColor="@color/colorPrimary"
            android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
</vector>

您可以使用Android Studio本身的铅笔图标,从
文件->新建->矢量资源-/code>点击剪贴画图标
并搜索您的特定图像。您还可以通过其XML更改其颜色

或者,您可以从下载SVG图像并选择所需的图像。在Android Studio中使用后,还可以从XML更改其颜色

矢量可绘制铅笔图标的示例XML

<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:fillColor="#FF000000"
    android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>


您所说的“xml定义”是指可矢量绘制的吗?不是。。简单的可拉伸的。。使用shape object,我想这是不合理的。你可能不得不将你的思想放松到堆叠形状层,旋转并正确定位每一层。您最好的选择是矢量绘图。或者SVG文件(例如,它需要一个外部库,但在InkScape中很容易编辑)。