具有文本密码输入类型的Android EditText不会通过双击选择所有字符

标签 android android-edittext passwords selectall

我正在尝试将 EditTexttextPassword 输入类型结合使用。我遇到这样一种情况,即在 android 版本 5 和 4.4 中通过双击选择输入该字段的所有字符,而此功能在 android 版本 6 上不起作用。 您能帮我在所有 Android 版本中使用此功能吗?

这是我的 xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <EditText
        android:hint="Text Password Input Type"
        android:inputType="textPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

这是结果:

enter image description here

最佳答案

一般的算法是:

private long timeLastClicked;
private static final TIME_DOUBLE_CLICK_MS = 1000;
private EditText passwordField;  //should put the result of findViewById in here

...

myEditText.setOnClickListener(new OnClickListener() {
    public void onClick(View view) {
        long time = System.currentTimeMillis();
        if(time - timeLastClicked < TIME_DOUBLE_CLICK_MS) {
           passwordField.setSelection(0,passwordField.getText().length());
        }
        timeLastClicked = time;
});

这是做什么的 - 它设置了一个点击监听器。当您看到一次点击时,您会检查您是否已经在前一秒看到了另一次点击。如果是,则突出显示文本。如果没有,你就不会。无论哪种方式,您都可以节省这次点击的时间,以便下次进行比较。

关于具有文本密码输入类型的Android EditText不会通过双击选择所有字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45778953/

相关文章:

authentication - 为什么不允许密码认证?

c# - 在 WPF 中同时验证多个控件

android - 在 updateChildren 中断功能后立即清除 HashMap

android - 更新Android中特定布局的DrawingCache

android - AutoCompleteTextView 光标应移动到下一个 AutoCompleteTextView/EditTextBox 选择建议

java - 使用 for 循环将 EditText 添加到 android 中的布局

php - 最佳加密技术

java - 如何在指定日期之前在Android中设置通知

Android:为什么使用图像按钮?

java - 在 firebase 中使用随 secret 钥获取子节点数据的最佳方法?