我有一个包含多行的 EditText
,由 Google 地址 API 生成的地点 + 换行符 + 地址组成。
当屏幕显示时,我想让文本光标位于地名末尾(第一行末尾)而不是 EditText
中的第一个字符。
String text = placeName + "\n" + addressName;
TextView tv = findViewById(R.id.placeAddress);
tv.setText(text);
最佳答案
对上面的代码稍作修改
String text = placeName + "\n" + addressName;
EditText et = findViewById(R.id.placeAddress);
et.setText(text).setSelection(placeName.length());
关于java - 如何将焦点集中在文本中间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56284756/