android - 同时在 editText 中提示和文本

标签 android text android-edittext hint

我只需要一个 editText,我可以在其中同时设置文本和提示。 例如,我希望用户输入像 user#1234 这样的 editText 字符串 在此字符串中,user# 应该是数字会有所不同之后的文本,因此当用户尝试输入光标时,1234 应该显示为提示将在 # 之后显示,而当用户键入字符时,1234 提示将消失。

请指导我如何做到这一点。

谢谢

最佳答案

我设法通过一些技巧并使用 marginpadding 实现了这一点

这是我做的

<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/

相关文章:

android - onFocus 功能在 Android 中无法正常工作?

android - DialogFragment 中的 ViewPager2 内的 EditText 不会显示键盘

android - EditText 不专注于触摸

c - 缩小位图字体的算法

javascript - JS 更改文本 onClick 然后改回 onClick If...else

android - 如何使用字符串变量通过 id 查找 View ?

android - 在 Android Studio 项目中包含 OpenCV 会产生 'Unresolved dependencies' 错误

java - 单行 JTextArea

android - Kotlin中如何使用OKHTTP发送post请求?

java - RecyclerView 内部 fragment 在 Android API 22 中不滚动