在我的应用程序中,当我从一种活动转到另一种软键盘时,会自动弹出。

我进行了一项活动(说A)

  android:configChanges="keyboardHidden"


因为我不想在此活动上使用键盘,但是当我从该活动转到包含Map和AutoComompleteTextView的另一个活动(例如B)时,键盘会先自动弹出然后关闭。

我对活动B所做的尝试:
在清单中我已经设定

android:windowSoftInputMode="stateHidden|adjustResize"


在oncreate中

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);


我也尝试将其放在OnCreate中

  try{
        View view = this.getCurrentFocus();
        if (view != null) {
            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }catch (Exception e)
    {
        Log.e(TAG, "onCreate: keyboard crash");
        e.printStackTrace();
    }


我还尝试将重点放在活动中的另一个视图上,例如(View v1)

 v1.requestFoucs();


我什至尝试把

android:focusableInTouchMode="true"


在活动B的每个组成部分上。

但对我没有任何作用。

请帮我解决这个问题
我已经尝试了属于下面链接列表的所有已接受的ans:

OnScreen keyboard opens automatically when Activity starts

Automatic popping up keyboard on start Activity

How to avoid automatically appear android keyboard when activity start

这是我的AutoComompleteTextView

<AutoCompleteTextView
            android:id="@+id/auto_serviceArea"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginStart="10dp"
            android:layout_weight=".5"
            android:background="@android:color/transparent"
            android:cursorVisible="false"
            android:hint="@string/serviceArea"
            android:padding="5dp"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:singleLine="true"/>


编辑1:我试图检查哪个视图正在获得焦点,以便我可以转移该焦点,并且在调试时我从AutoCompleteTextView中删除了焦点,但是在活动开始时仍然出现键盘并消失了。
因此,这不是自动完成焦点问题。

最佳答案

如果您已根据问题的链接尝试了所有被接受的答案,那么为什么不尝试调试启动活动,我的意思是您打算启动相应的活动。
在调试我的一个应用程序时,我发现即使在完成调用它的活动后,Android软键盘也不会掉下来,但它会在屏幕上停留几秒钟,但这种情况并不经常发生。

因此,我建议您也调试调用活动,只需尝试将“ focusable = false”放在您从中调用相应活动的组件上即可。

07-28 03:25
查看更多