android - 有没有办法或内置方法从android材料TextInputLayout(om.google.android.material.textfield.TextInputLayout)获取文本?
问题描述
我曾尝试使用 getText() 但这在使用该文本字段时不可用,下面是文本字段:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/firstnametxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="120dp"
android:layout_marginRight="25dp"
android:hint="First Name">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
解决方案
TextInputLayout
有一个editText
字段,您可以将其转换为您的TextInputEditText
并使用它的text
字段获取其中的文本。例如在 Kotlin 中它看起来像
val editText = textInputLayout.editText as TextInputEditText
editText.text
推荐阅读
- python - 为 github repo 配置本地 python 包导入的最佳实践?
- python - 如果列字符串包含 X 和 [Y,Z] 中的至少一个,则捕获行
- xml - 如何使用 XSLT 交换两个 XML 节点?
- airflow - 创建用户后气流登录失败
- numbers - 考虑到n不是素数,如何找到具有n个因子的第i个数?
- python - 一个接一个地打印数字而不将它们加在一起Python
- python - Python 函数作用域
- for-loop - 我收到一条错误消息,说我的“for”限制不是数字,即使我没有引用该变量
- javascript - 如何只执行一次附加到函数的 v-html?
- amazon-redshift - redshift 按字符串的一部分对外部表进行分区