【问题标题】:Change focus of edittext when tap outsite edittext点击外部编辑文本时更改编辑文本的焦点
【发布时间】:2011-09-17 15:46:09
【问题描述】:

我有一个编辑文本来输入 url,还有一个 webview 来显示网站

我的问题是:当我访问 google.com 时,我点击了我的编辑文本,因此我的编辑文本具有焦点。

我在谷歌点击搜索区域,但我的编辑文本没有失去焦点。

点击外部edittext时如何更改edittext的焦点?

【问题讨论】:

    标签: android focus android-edittext


    【解决方案1】:

    从这里获得答案:EditText, clear focus on touch outside

    这里:

    Android: Force EditText to remove focus?

    你可以让光标和焦点消失

    edittext.clearFocus();
    

    【讨论】:

      【解决方案2】:

      做某事就行了

      /**
       * hide soft keyboard
       */
      private void hideSoftKeyboard() {
          InputMethodManager inputManager = (InputMethodManager) getBaseContext()
                  .getSystemService(Context.INPUT_METHOD_SERVICE);
          if (inputManager != null)
              inputManager.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);       
      }
      
      @Override
      public boolean onTouch(View view, MotionEvent event) {
          if(view == mWebView) {
              hideSoftKeyboard();
          }
          return false;
      }
      

      【讨论】:

      • 这个答案只会隐藏键盘,但不会改变 EditText 框的焦点。
      猜你喜欢
      • 1970-01-01
      • 2014-11-17
      • 1970-01-01
      • 2018-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-28
      相关资源
      最近更新 更多