I have a TextInputEditText
field to write numbers down. I want to add a drawable symbol to the end of my InputText
which already worked.
The problem is, that my text and the drawable are not the same size...So I want to resize the drawable to the same size as my text. How could I do this?
The XML code is here:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/green"
android:orientation="horizontal"
android:weightSum="2"
android:padding="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="amount"
android:layout_weight="1"
android:gravity="left"
android:textColor="@color/white"
android:textSize="15dp"/>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/amount_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="numberDecimal"
android:textAlignment="textEnd"
android:background="@color/transparent"
android:textSize="15dp"
android:drawableEnd="@drawable/ic_percent"/>
</LinearLayout>
Here is an example how it looks right now:
I found an answer, so I would like to share it with you:
val drawable1: Drawable=inputField.compoundDrawablesRelative[position] //get Drawable from Input
drawable1.setBounds(0,0,15.toPx(),15.toPx()) // set size
inputField.setCompoundDrawables(null,null,symbol1,null) // set position of drawable