从一个 activity 移动到另一个时键盘自动弹出

keyboard automatic pops up when moving from one activity to another

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

我有一个 activity(Say A) 我已经设置了

  android:configChanges="keyboardHidden" 

因为我不想在这个 activity 上使用键盘,但是当我从这个 activity 移动到另一个包含 Map 和 AutoCompleteTextView 的 activity(比如 B)时,键盘首先自动弹出然后关闭。

我在 activity 上试过的东西 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();
    }

我还尝试将焦点设置在 activity 中的另一个视图,例如(视图 v1)

 v1.requestFoucs();

我什至试过

android:focusableInTouchMode="true"

在 activity B.

的每个组件上

但对我没有任何作用。

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

OnScreen keyboard opens automatically when Activity starts

Automatic popping up keyboard on start Activity

How to avoid automatically appear android keyboard when activity start

这是我的 AutoCompleteTextView

<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 中删除了焦点,但是当 activity 启动时键盘仍然出现又消失。 所以这不是自动完成焦点问题。

你只需要给

android:windowSoftInputMode="stateHidden"

在您 Activity 的清单文件中。

在您的主要 xml 标签内写下一行

android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"

如下

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainLayout"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true" >

java 文件中使用这些行:

InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
inputManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);

如果您已经根据您的问题链接尝试了所有被接受的答案,那么为什么不尝试调试您的开始 activity,我的意思是您有意开始各自的activity。 在调试我的一个应用程序时,我发现 android 软键盘有一个问题,即使在完成调用它的 activity 之后也不会下降,它会在屏幕上停留几秒钟,但这种情况并不经常发生.

所以我建议您也调试调用 activity,只需尝试将 "focusable=false" 放在您调用相应 activity.

的组件上