我正在尝试将 EditText
与 textPassword
输入类型结合使用。我遇到这样一种情况,即在 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>
这是结果:
最佳答案
一般的算法是:
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/