【问题标题】:how to avoid "actionDone" for EditText如何避免 EditText 的“actionDone”
【发布时间】:2016-02-16 19:54:18
【问题描述】:

我正在尝试为我的 EditText 显示软键盘。这里我遇到了关于 imeoptions 的问题。我的要求是:当切换软键盘时,actionDone 永远不应该对用户可见。actionNext 应该始终可见。 我面临的是:当用户切换键盘时,它第一次显示 actionNext 但是当用户键入数据然后单击键盘切换器时,它显示 actionDone 选项。但这里我只想要 actionNext。此外,如果用户清除该字段并且再次切换键盘,它只显示 actionDone 而不是 actionNext。 结论:在任何情况下,我都只想要 actionNext。 这是我切换软键盘的代码:

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

                  }
               });

提前致谢。

【问题讨论】:

    标签: android android-edittext android-softkeyboard imeoptions


    【解决方案1】:

    事实上,我们不能禁用安卓键盘上的完成(回车)操作按钮。

    但我们只能通过将 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;
        }
      }
    });
    

    【讨论】:

      【解决方案2】:

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

      actv_ServiceLoc.setInputType(InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
      //your ui control.setInputType(InputType.YourFlag);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-14
        • 2012-09-29
        • 1970-01-01
        • 1970-01-01
        • 2017-07-17
        相关资源
        最近更新 更多