2017-08-20 27 views
2

我试图使用EditTexttextPassword输入类型。我面临的情况是,在Android版本5和4.4中,所有进入该字段的字符都是通过双击来选择的,而此功能在Android版本6上不起作用。 您是否愿意帮助我在所有Android版本中拥有此功能?带有文本密码输入类型的Android EditText不会通过双击选择全部字符

这是我的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

+0

我想这个问题是只用模拟器而不是真正的设备 – VVB

+0

@VVB这个功能在Samsung Note 4上用Lollipop和Nexus 5与Marshmallow android版本进行了检查。发生了同样的结果。 – Nava

回答

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; 
}); 

这是什么does-它集点击监听器。当你看到一个点击时,你检查你是否已经在前一秒看到另一个点击。如果是这样,你高亮文本。如果没有,你不会。无论哪种方式,您都可以节省点击时间,以便下次进行比较。

+0

你测试过这个解决方案吗?没有为我工作。看来问题涉及到setSelection()方法。因为算法是正确的。 – Nava

相关问题