如何解决从具有前缀的文本输入布局内的编辑文本中获取文本
我有一个文本输入编辑布局,其中 TextInputEditText 的前缀为 +254
下面是文本输入布局的代码
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_phone_number"
android:layout_below="@+id/rl_text_view_login_description"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:padding="5dp"
app:prefixText="+254">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_phone_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Phone Number"
android:inputType="text"
android:textSize="15sp"/>
</com.google.android.material.textfield.TextInputLayout>
我遇到的问题是,当我从文本输入编辑文本中获取文本时,它没有获取前缀,它只能获取输入的文本。我怎样才能得到带有前缀的整个文本
下面是我如何获取文本
etPhoneNumber.getText().toString().trim()
我试过删除trim(),但没有得到prefixText
解决方法
您可以在“TextInputLayout”对象 (til_phone_number) 上使用 getPrefixText()
方法获取前缀文本..
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。