0

I am trying to display softkeyboard for my EditText.Here I am having a problem regarding imeoptions.my requirement is : actionDone should never be visible to user when toggle softkeyboard.always actionNext should be visible. What i am facing is: when user toggle keyboard,for first time it shows actionNext but when user type data and then click on keyboard toggler it is showing actionDone option.but here i want actionNext only.Beside,if the user clears the field and again toggle keyboard it is showing actionDone only but not actionNext. conclusion:i want only the actionNext in any scenario. this is my code for toggling softkeyboard:

btn_keyboard.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {
         //actv_ServiceLoc.setInputType(InputType.TYPE_CLASS_TEXT);
         InputMethodManager inputMgr = (InputMethodManager)                      
           getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
         //inputMgr.toggleSoftInput(EditorInfo.IME_ACTION_NEXT,   
          EditorInfo.IME_ACTION_DONE);
      inputMgr.toggleSoftInput
       (EditorInfo.IME_FLAG_NO_ENTER_ACTION,EditorInfo.IME_ACTION_DONE);
       //actv_ServiceLoc.setText("");

        actv_ServiceLoc.requestFocus();
       if(actv_ServiceLoc.getText().toString().length()==0) {
        actv_ServiceLoc.setImeOptions(EditorInfo.IME_ACTION_NEXT);
         }
         else
              {
           actv_ServiceLoc.setImeOptions(EditorInfo.IME_ACTION_NEXT);

              }
         actv_ServiceLoc.setFocusableInTouchMode(true);
               location_error.setVisibility(myView.GONE);

                  }
               });

Thanks in advance.

4

2 回答 2

1

事实上,我们不能禁用 android 键盘上的完成(输入)操作按钮。

但是我们只能通过将 android:imeOptions="actionDone" 添加到您的 EditText 来禁用下一个按钮。

然后控制完成按钮的最后一个解决方案是使用以下代码块:

EditText txtEdit = (EditText) findViewById(R.id.txtEdit);
txtEdit.setOnEditorActionListener(new OnEditorActionListener() {

  public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_DONE) {
      // your additional processing... 
      return true;
    } else {
      return false;
    }
  }
});
于 2015-11-15T18:23:06.957 回答
0

在切换键盘之前在单行下方书写有助于您在键盘中始终显示“actionNext”按钮。

actv_ServiceLoc.setInputType(InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
//your ui control.setInputType(InputType.YourFlag);
于 2015-11-24T08:03:06.093 回答