Select all text inside EditText when it gets focus
I have an EditText with some dummy text in it. When the user clicks on it I want it to be selected so that when the user starts typing the dummy text gets deleted.
How can I achieve this?
你可以在你的main.xml
文件中尝试:
android:selectAllOnFocus="true"
editText.setSelectAllOnFocus(true);
如果你想以编程方式执行它,这是有效的。
EditText dummy = ...
// android.view.View.OnFocusChangeListener
dummy.setOnFocusChangeListener(new OnFocusChangeListener(){
public void onFocusChange(View v, boolean hasFocus){
if (hasFocus) && (isDummyText())
((EditText)v).selectAll();
}
});
链接地址: http://www.djcxy.com/p/24182.html
上一篇: 在启动Activity时自动弹出键盘