如何在EditText中提示后将焦点设置为文本?

时间:2012-11-07 14:40:52

标签: java android input focus android-edittext

我对您感兴趣,可以在提示EditText后将焦点设置为文本?如果xml布局没有这样的属性?在那时我仍然看起来像这样。

enter image description here

需要

enter image description here

编辑:
Asok 的最快和最有效的答案 我也发现了类似的方式:
EditText.append(" 60&#34); // 60或您在EditText中的文字

2 个答案:

答案 0 :(得分:3)

提示不是真实文本,在用户输入内容后消失。假设光标位于提示的末尾,当用户按下按钮并且提示消失时,您会期望什么行为?

您可以做的是通过

在XML中设置默认文本
android:text="60"

或代码通过

editText.setText("60");

并且焦点通过

跳转到EditText的末尾
editText.setSelection(editText.getText().length());

答案 1 :(得分:0)

如果我理解正确您希望将光标放在提示文本后面,如果这是正确的,那么就不可能,您必须删除提示并改为使用setText,如下所示:

EditText et = (EditText)findViewById(R.id.sixtyseconds);
et.setText("60");
et.setSelection(et.getText().length());
相关问题