2016-08-04 28 views
2

在我的应用程序中,我实现了一个我自己的号码簿,用于输入(基于数字)密码。 '密码',或者说'点'表示,显示在num-pad上方4个框中的4个EditText中。当你输入一个数字时,其中的一个框会填充一个点 - 为此,我使用TransformationMethod PasswordTransformationMethod - 但我希望在打开隐藏数字之前让其突出显示一段时间(比如〜200ms )。在隐藏它们之前显示密码字符一小会儿

在Android中有没有这方面的实现,或者你会如何实现这个最好的方式?我相信你知道我的意思,它很常用于基于移动的密码输入。

编辑:代码提示后:

codeField1 = (EditText) findViewById(R.id.passcode_1); 
codeField2 = (EditText) findViewById(R.id.passcode_2); 
codeField3 = (EditText) findViewById(R.id.passcode_3); 
codeField4 = (EditText) findViewById(R.id.passcode_4); 

new Handler().postDelayed(new Runnable() { 
     @Override 
     public void run() { 
      codeField1.setTransformationMethod(PasswordTransformationMethod.getInstance()); 
      codeField2.setTransformationMethod(PasswordTransformationMethod.getInstance()); 
      codeField3.setTransformationMethod(PasswordTransformationMethod.getInstance()); 
      codeField4.setTransformationMethod(PasswordTransformationMethod.getInstance()); 
     } 
    }, 2000); 

仍然给我的问题,仅在第一个我进入效果。(所有这一切都在的onCreate())。

回答

2

试试这个代码..

这之后2秒隐藏文本,你可以根据你的requi改变它..

new Handler().postDelayed(new Runnable() { 
     @Override 
     public void run() { 
      edittext.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); 
      editText.setTransformationMethod(PasswordTransformationMethod.getInstance()); 
     } 
    }, 2000); // set time based on your requirement 
+0

会试试看,欢呼! –

+0

我会在哪里放置该代码片段?我在哪里启动我的EditTexts或在我的onClick()..?或者别的地方?在编辑文本初始化之后,在编辑文本初始化之前,在编辑文本 –

+1

之前没有真正与处理程序合作过。 –

2

使用TextWatcher

不要设置在edittext.Instead的android:password="true"财产使用textwatcher并在textwatcher addTextChangedListener()等待200毫秒后更换*密码。

要等待使用下面的代码:

private Handler mHandler = new Handler(); 
mHandler.postDelayed(new Runnable() { 
      public void run() { 
       doStuff(); 
      } 
     }, 2000); 
+0

完全集中在另一个解决方案上,因为它像你之前的30秒一样进来,哈哈 - 但是看起来你似乎有点类似。感谢您伸出援助之手! –