2016-12-05 96 views
0

我正在开发一个Android应用程序,并且需要用户输入密码。当用户按下完成或输入按钮时,软键盘将消失。 当密码错误,我想让软键盘仍然在屏幕上不晃动。因为我现在的解决方案是让它消失并将其重新显示在屏幕上,键盘抖动会发生,我认为这是糟糕的设计。 所以问题是我怎样才能保持软键盘始终显示在屏幕上甚至用户按下输入按钮?Android保持软键盘显示输入完成时按钮

回答

1

你的密码的EditText像检查密码本

<EditText 
     android:id="@+id/editText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:ems="10" 
     android:imeOptions="actionDone" 
     android:inputType="textPassword" /> 

Java代码。 例如:密码ID 12345

EditText editText = (EditText) findViewById(R.id.editText); 
       editText.setOnEditorActionListener(new TextView.OnEditorActionListener() { 
        @Override 
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
         boolean handled = false; 
         if (actionId == EditorInfo.IME_ACTION_DONE) { 
          if (v.getText().toString().equals("12345")) { 
          // if the pass word is 12345 
           // hide your keyboard code 
           Log.e("[email protected]@ ", "true"); 
          } else { 
        // if password is not 12345 
         // not hide keyboard code 
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); 
           Log.e("[email protected]@ ", "false"); 
          } 
          handled = true; 
         } 
         return handled; 
        } 
       }); 
+0

我已经写了类似的解决方案中的代码,但我认为它并没有解决我的问题,我的问题是如何能保持软键盘显示时的密码是不是12345。 –

+0

检查我的更新回答.. –