开发者

how to Remove text onfocus of EditText in android?

开发者 https://www.devze.com 2022-12-21 15:45 出处:网络
I have a scenario, for example, a EditText in acitivityinstead 开发者_如何学Goof using Textview as a label of it i want to put text \"UserName\" inside EditText and if user clicks on it.

I have a scenario, for example, a EditText in acitivity instead 开发者_如何学Goof using Textview as a label of it i want to put text "UserName" inside EditText and if user clicks on it. it should disappear and EditText should get empty to enter data in it.

How can I achieve this?


android:hint="username"

put this attribute in EditText

thats it.


onclickListener does not work with EditText items, you'll have to use an OnFocusListener.


Use setOnClickListener() to register a listener that then checks if the EditText just contains "UserName", and clears it out if that is true.

0

精彩评论

暂无评论...
验证码 换一张
取 消