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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With