Display a message inside Android Edit Text Field

我们两清 提交于 2019-12-10 12:58:36

问题


Hai, I have an Android Program with one text field. I need to display a message inside that textfield when it loads on an emulator. When the user clicks inside that textbox that message should dispappear. For Ex: Please enter name Can any one post some sample code over here...


回答1:


Just use or call setHint on the object. Hint text to display when the text is empty.

<EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="18px"
        android:gravity="left"
        android:hint="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse egestas ullamcorper facilisis." />



回答2:


You need to use the attribute Hint of the EditText.

android:hint in your xml
setHint(int) at runtime

This will execute just what you need



来源:https://stackoverflow.com/questions/3318083/display-a-message-inside-android-edit-text-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!