問(wèn)題描述
在 Android 中,如何在點(diǎn)擊時(shí)清除 EditText
?
In Android how can I make an EditText
clear when it's clicked?
例如,如果我有一個(gè) EditText
,其中包含一些字符,例如 'Enter Name'
,那么當(dāng)用戶單擊它時(shí),這些字符就會(huì)消失.
E.g., if I have an EditText
with some characters in, such as 'Enter Name'
, when the user clicks on it these characters disappear.
推薦答案
我不確定你是否在追求這個(gè),但試試這個(gè) XML:
I'm not sure if you are after this, but try this XML:
android:hint="Enter Name"
當(dāng)輸入字段為空、選中或未選中時(shí),它會(huì)顯示該文本.
It displays that text when the input field is empty, selected or unselected.
或者,如果您希望它完全按照您的描述執(zhí)行,請(qǐng)?jiān)?editText 上分配一個(gè) onClickListener 并使用 setText() 將其設(shè)置為空.
Or if you want it to do exactly as you described, assign a onClickListener on the editText and set it empty with setText().
這篇關(guān)于如何在點(diǎn)擊時(shí)清除 EditText?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!