我正在尝试将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>
结果如下:
答案 0 :(得分:0)
通用算法将是:
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;
});
这是做什么的 - 它设置了一个点击监听器。当您看到一个单击时,检查您是否在前一秒中看到了另一次单击。如果是这样,你就会使文字变暗。如果没有,你就不会。无论哪种方式,您都可以节省此次点击的时间,以便下次进行比较。