简体   繁体   English

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

[英]How to set focus to the text after the hint in EditText?

I'm interested in you can set the focus to the text after the prompt to EditText? 我感兴趣的是,您可以在提示输入EditText吗? If no such attribute for xml layout? 如果没有这样的XML布局属性? At the moent I still looked like this. 在那一刻,我仍然看起来像这样。

在此处输入图片说明

need 需要

在此处输入图片说明

EDIT : 编辑:
The fastest and working answer given Asok Asok最快,最有效的答案
I also found a similar way: 我还发现了类似的方法:
EditText.append("60"); EditText.append(“ 60”); // 60 or your text in EditText // 60或您在EditText中的文本

A hint is no real text, it disappears after the user types something. 提示不是真实文本,在用户键入内容后消失。 Assuming the cursor would be at the end of the hint what behaviour would you expect when the user presses a button and the hint disappears? 假设光标将在提示的末尾,当用户按下按钮并且提示消失时,您期望什么行为?

What you can do is set a default text in the XML via 您可以通过以下方式在XML中设置默认文本:

android:text="60"

or in code via 或通过代码

editText.setText("60");

and on focus jump to the end of the EditText via 并专注于通过跳转到EditText的末尾

editText.setSelection(editText.getText().length());

If I understand correctly you are looking to place the cursor behind the hint text, if this is correct then it is not possible, you'll have to remove hint and use setText instead, like so: 如果我理解正确,那么您正在将光标放置在提示文本的后面,如果这是正确的,那么这是不可能的,您将必须删除提示并使用setText ,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM