android - 如何在 android 的 TextInputLayout 中对齐文本?
问题描述
在RelativeLayout
我有一个TextInputLayout
我在EditText
里面输入电话号码的地方和一个我在Textview
里面LinearLayout
显示国家代码的地方。当我们开始输入 `TextInputLayout 时滑动到顶部,但我希望它像图 3 那样滑动到顶部。
我在这方面面临问题有人可以帮助我吗?这是我的代码:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/error_mobile_no"
android:layout_alignTop="@+id/error_mobile_no"
android:layout_alignBottom="@+id/error_mobile_no"
android:layout_marginTop="0dp"
android:layout_marginBottom="0dp"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/country_code_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/lorin_regular"
android:text="+971"
android:layout_marginBottom="2dp"
android:textColor="@color/black"
android:textSize="14sp" />
</LinearLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/error_mobile_no"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
app:errorEnabled="true">
<EditText
android:id="@+id/etPhoneNumberDetailedActivity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:autofillHints=""
android:paddingStart="35dp"
android:backgroundTint="#6283a3"
android:fontFamily="@font/lorin_regular"
android:hint="@string/mobile_number"
android:inputType="phone"
android:textColor="@color/black"
android:textColorHint="#6283a3" android:textSize="14sp" />
</com.google.android.material.textfield.TextInputLayout>
</RelativeLayout>
解决方案
您可以使用app:prefixText
来显示前缀:
<com.google.android.material.textfield.TextInputLayout
android:hint="mobile_number"
app:prefixText="+971"
...>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:autofillHints=""
android:inputType="phone"
.../>
</com.google.android.material.textfield.TextInputLayout>
推荐阅读
- google-analytics - 当我使用谷歌分析时,我在标签上绑定了点击触发器,但是名为 collect 的请求被取消了,
- c++ - POCO Websocket 中传入消息的 Aysnc 处理程序
- amazon-web-services - 单个 aws cli 命令可以执行“从单个源文件到多个目标文件的 aws s3 cp”吗?
- python - UnicodeEncodeError:“ascii”编解码器无法对位置 15-17 中的字符进行编码:序号不在范围内(128)
- php - 使用 ACF 组的嵌套中继器
- azure-active-directory - 错误:AADSTS90015:请求的查询字符串太长(在执行 ADFS 时)
- python - 有人可以解释一下如何在 python 上为 selenium 编写 xpath 吗?
- php - Laravel - 将大量条目保存到数据库
- itext7 - Itext7 - 在没有分页符的情况下合并 PDF
- go - 返回数组作为接口