我有一个TextInputEditText字段要写下数字.我想在我的InputText的末尾添加一个可绘制的符号,它已经起作用了.

问题是,我的文本和可绘制文本的大小不同……所以我想将可绘制文本的大小调整到与我的文本相同的大小.我怎么能这么做?

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>

下面是一个现在看起来是什么样子的例子:

enter image description here

推荐答案

我找到了一个答案,所以我想和大家分享一下:

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

Android相关问答推荐

为什么R8不混淆某些类?

如何检测HitTest是否命中给定的网格对象?

泛型类型lambda函数参数作为函数参数

关闭导致Kotlin中的内存泄漏?

如何将Unicode符号作为文本居中放置在布局中的按钮(Android XML)中?

在Jetpack Compose中,如何判断屏幕是否已重新组合?

Jetpack Compose:带芯片的Textfield

在内部创建匿名对象的繁忙循环调用函数会产生开销吗?

设置文本 colored颜色 动画时如何减少重新组合?

尽管我在onCreate()期间已经初始化,但仍出现未初始化的late init变量错误

错误:无法安装应用程序:INSTALL_PARSE_FAILED_MANIFEST_MALFORMED (React-Native-Android-Studio)

Jetpack Compose 动画的行为是什么?

如何在 JetpackCompose 的 LazyColumn 中 Select 多个项目

PayUCheckoutPro Android SDK 实现问题

单击 Jetpack Compose(单选)时,我无法为列表中的单个文本着色

在 Google Play 中将用户从开放测试转移到生产的过程是怎样的?

ionic - capacitor - Android 风味 - 无法在模拟器或真实设备中运行应用程序

如何在屏幕旋转或系统主题更改后将光标移动到 TextField 的末尾并保持键盘显示?

使 Compose LazyColumn 的最后一项填满屏幕的其余部分

在使用 Retrofit 和 Room 时,我是否需要提及协程调度程序?