【问题标题】:Getting text from Edit Text inside Text Input Layout that has a prefix从具有前缀的文本输入布局内的编辑文本中获取文本
【发布时间】:2021-06-12 08:52:03
【问题描述】:

我的文本输入编辑布局带有前缀为 +254 的 TextInputEditText

下面是文本输入布局的代码


<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

【问题讨论】:

    标签: android gettext prefix android-textinputlayout android-textinputedittext


    【解决方案1】:

    您可以在“TextInputLayout”对象 (til_phone_number) 上使用 getPrefixText() 方法获取前缀文本 ..

    链接:- https://developer.android.com/reference/com/google/android/material/textfield/TextInputLayout#getPrefixText()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-25
      • 2013-01-02
      • 1970-01-01
      • 2012-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多