android - 当 EditText 有焦点时选择所有文本不起作用
问题描述
当 EditText 有焦点时,我想默认选择里面的所有文本,但它不起作用:
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (hasFocus) {
// Go to the end
editText.setSelection(getEditTextView().getText().length());
// Select all the content
editText.selectAll();
}
}
});
非常感谢你们!
解决方案
有 2 种好方法可以在 EditText 中选择文本:
在你的 main.xml 里面:
android:selectAllOnFocus="true"
或者 :
editText.setSelectAllOnFocus(true);
(如果你想以编程方式进行)
推荐阅读
- r - 根据条件整理一个数据框中的行
- nginx - Nginx 多工作负载配置 - 网站和反向代理
- tabulator - 循环遍历制表符的数组
- java - 我试图将 JLabel 放在 JButton 上,但是当我将鼠标指针放在标签上时,它消失了
- c - 需要帮助解析“|” 文件中的分隔线
- javascript - tabs.filter 不是一个函数
- google-apps-script - 脚本条件格式在手动覆盖之前不起作用
- java - 无法从 Firebase 检索信息到自定义 ListView Android
- zsh - zsh 函数将任意字符串放入行编辑器
- html - aria-label 与表单标签