我只需要一个 editText,我可以在其中同时设置文本和提示。 例如,我希望用户输入像 user#1234 这样的 editText 字符串 在此字符串中,user# 应该是数字会有所不同之后的文本,因此当用户尝试输入光标时,1234 应该显示为提示将在 # 之后显示,而当用户键入字符时,1234 提示将消失。
请指导我如何做到这一点。
谢谢
最佳答案
我设法通过一些技巧并使用 margin
和 padding
实现了这一点
这是我做的
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp" >
<TextView
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="right"
android:text="user#" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="1234"
android:paddingLeft="40dp"
android:textSize="14sp" />
</RelativeLayout>
希望对你有帮助
关于android - 同时在 editText 中提示和文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36153633/