为什么我的 SVG 图标在 Android 中可绘制的 EditText 中这么大?

Why My SVG Icon Size so larg In EditText Drawable In Android?

当我在 victor asset 中制作 SVG 文件并使其成为 editText 的可绘制文件时,它看起来太大了,我看到很多视频他们创建了新的 victor asset 并选择 "SVG" 文件并将其设为 "XML" 文件 我为 EditText 制作了 drawableStart,但它太大了,不像我制作所有步骤的视频,但它总是失败。

这是它的样子:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ListView">


  <EditText
    android:id="@+id/editText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#17FFFFFF"
    android:drawableStart="@drawable/ic_search"
    android:drawableLeft="@drawable/ic_search"
    android:ems="10"
    android:inputType="textPersonName"
    android:textSize="32dp" />

</LinearLayout>

SVG

<vector
    android:alpha="0.85"
    android:autoMirrored="true"
    android:height="512.005dp"
    android:viewportHeight="512.005"
    android:viewportWidth="512.005"
    android:width="512.005dp"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <path
       android:fillColor="#FF000000"
       android:pathData="M505.749,475.587l-145.6,-145.6c28.203,-34.837 45.184,-79.104 45.184,-127.317c0,-111.744 -90.923,-202.667 -202.667,-202.667S0,90.925 0,202.669s90.923,202.667 202.667,202.667c48.213,0 92.48,-16.981 127.317,-45.184l145.6,145.6c4.16,4.16 9.621,6.251 15.083,6.251s10.923,-2.091 15.083,-6.251C514.091,497.411 514.091,483.928 505.749,475.587zM202.667,362.669c-88.235,0 -160,-71.765 -160,-160s71.765,-160 160,-160s160,71.765 160,160S290.901,362.669 202.667,362.669z"/>
</vector>

将矢量大小调整为 24dp,这是 android studio 中任何图标的默认大小。导入时更改大小。

<vector
android:alpha="0.85"
android:autoMirrored="true"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0"
android:width="24dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
   android:fillColor="#FF000000"
   android:pathData="M505.749,475.587l-145.6,-145.6c28.203,-34.837 45.184,-79.104 45.184,-127.317c0,-111.744 -90.923,-202.667 -202.667,-202.667S0,90.925 0,202.669s90.923,202.667 202.667,202.667c48.213,0 92.48,-16.981 127.317,-45.184l145.6,145.6c4.16,4.16 9.621,6.251 15.083,6.251s10.923,-2.091 15.083,-6.251C514.091,497.411 514.091,483.928 505.749,475.587zM202.667,362.669c-88.235,0 -160,-71.765 -160,-160s71.765,-160 160,-160s160,71.765 160,160S290.901,362.669 202.667,362.669z"/>

change these two lines of svg xml. From

android:height="512.005dp"
android:width="512.005dp"

To

android:height="24dp"
android:width="24dp"

You can manage svg size according to EditText size