从 Kotlin 中的 MaterialDesigns 获取 TextInputLayout 的文本
Get text of TextInputLayout from MaterialDesigns in Kotlin
我在其他帖子中看到的基本代码似乎无法解决问题。它无法识别 未解决的参考文献:文本
val name = binding.etName.text.toString()
这是我的 XML 我有 etName 的地方,我还尝试将 etName id 标记放在 TextInputLayout 中以防万一
android:id="@+id/textInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_marginTop="15dp"
android:autofillHints=""
android:ems="10"
android:hint="@string/name"
android:inputType="textPersonName"
android:minHeight="48dp"
android:textColorHint="#0B0B0B"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="20dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>```
就用
textInputLayout.editText?.text?.toString() ?: ""
我在其他帖子中看到的基本代码似乎无法解决问题。它无法识别 未解决的参考文献:文本
val name = binding.etName.text.toString()
这是我的 XML 我有 etName 的地方,我还尝试将 etName id 标记放在 TextInputLayout 中以防万一
android:id="@+id/textInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_marginTop="15dp"
android:autofillHints=""
android:ems="10"
android:hint="@string/name"
android:inputType="textPersonName"
android:minHeight="48dp"
android:textColorHint="#0B0B0B"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="20dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>```
就用
textInputLayout.editText?.text?.toString() ?: ""