DrawableLeft with xml icon

Wot*_*aio 2 android android-layout

How to use drawableLeft with an xml icon? I have the following button:

<Button
   android:id="@+id/vitimas"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:layout_marginBottom="10dp"
   android:layout_marginLeft="20dp"
   android:layout_marginRight="20dp"
   android:drawableLeft="@drawable/ic_person_black_24dp"
   android:drawableStart="@drawable/ic_person_black_24dp"
   android:background="@drawable/botao_verde"
   android:text="Vítimas"/>
Run Code Online (Sandbox Code Playgroud)

In old APIs such as 16, the app stops working due to drawableLeft, I tried to use an ImageButton but the same happens, if I use app: srcCompat it works, however the icon is not stay in left, I need it to be stay in left and the text in the middle

The icon is from the Vector Asset package.

Dar*_*ish 6

AppCompatTextView 支撑 app:drawableLeftCompatapp:drawableTopCompatapp:drawableRightCompatapp:drawableBottomCompatapp:drawableStartCompatapp:drawableEndCompat化合物可绘,支持向后移植可拉伸类型如VectorDrawableCompat

将此包含在您的 gradle 文件中

implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.appcompat:appcompat-resources:1.1.0-rc01'
Run Code Online (Sandbox Code Playgroud)

在您的文本视图中,您可以使用

app:drawableLeftCompat
app:drawableStartCompat
Run Code Online (Sandbox Code Playgroud)