Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DrawableLeft with xml icon

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"/>

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.

like image 251
Woton Sampaio Avatar asked Oct 16 '25 14:10

Woton Sampaio


1 Answers

AppCompatTextView supports app:drawableLeftCompat, app:drawableTopCompat, app:drawableRightCompat, app:drawableBottomCompat, app:drawableStartCompat and app:drawableEndCompat compound drawables, supporting backported drawable types such as VectorDrawableCompat.

Include this in your gradle file

implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.appcompat:appcompat-resources:1.1.0-rc01'

In your text view you can use

app:drawableLeftCompat
app:drawableStartCompat
like image 128
Darish Avatar answered Oct 18 '25 09:10

Darish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!