【问题标题】:show soft keyboard after already hidden and editbox focused在已经隐藏和编辑框聚焦后显示软键盘
【发布时间】:2013-03-28 14:58:17
【问题描述】:

我有一个只能在 2.3 设备上重现的问题。 基本上,我有一个带有两个 EditText 的活动,它们都是可聚焦的,用户可以在其中输入任何内容。 当我从纵向切换到横向时,我有一个要求,即不应显示虚拟键盘。为此,在 OnConfigurationChanged 上,我使用 InputMethodManager 的 hideSoftInputFromWindow。 但是,如果假设字段 2 在纵向模式下聚焦,当我切换到横向模式时,该字段已聚焦但按下它不会打开键盘。 我什至强迫它打开:

edittext2.setOnClickListener(new OnClickListener() {
@Override
    public void onClick(View v) {
InputMethodManager keyboard = ( InputMethodManager )
getSystemService( Context.INPUT_METHOD_SERVICE );
keyboard.showSoftInput( v, InputMethodManager.SHOW_FORCED);

但键盘也没有出现。

似乎,因为它已经获得焦点并且之前的键盘被显示和隐藏,系统决定不打开另一个键盘。

你能给我推荐一个快速修复方法吗?

稍后

在调用 showSoftInput 之前使用这个小麻烦的解决方法终于解决了这个问题:

edittext2.clearFocus
edittext2.requestFocus

【问题讨论】:

    标签: android show hidden android-softkeyboard


    【解决方案1】:

    这个方法怎么样;

     public static void setKeyboardFocus(final EditText primaryTextField) {
        (new Handler()).postDelayed(new Runnable() {
            public void run() {
                primaryTextField.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 0, 0, 0));
                primaryTextField.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, 0, 0, 0));
            }
        }, 100);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-08
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 2019-02-07
      • 2015-08-10
      相关资源
      最近更新 更多