[英]How to resize drawable in a TextInputEdit
I have a TextInputEditText
field to write numbers down.我有一个
TextInputEditText
字段来写下数字。 I want to add a drawable symbol to the end of my InputText
which already worked.我想在已经工作的
InputText
末尾添加一个可绘制符号。
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: XML 代码在这里:
<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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.