简体   繁体   English

键盘隐藏在Android Lollipop上崩溃

[英]Keyboard Hidden crashes on android Lollipop

Does anyone solve the problem with keyboard hidden crash on android 5.0? 有谁解决了Android 5.0上键盘隐藏崩溃的问题? I've tried on 4.4.2 with the same code but it doesn't happen. 我尝试使用相同的代码在4.4.2上,但不会发生。

This is my activity settings: 这是我的活动设置:

<activity
        android:name=".activity.MainActivity"
        android:configChanges="orientation|screenSize"
        android:hardwareAccelerated="true"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar">

This is the log after freezing 这是冻结后的日志

06-17 20:43:57.823 32593-32604/org.mydev.app.debug W/art: Suspending all threads took: 14.210ms
06-17 20:43:59.503 32593-32604/org.mydev.app.debug W/art: Suspending all threads took: 195.356ms
06-17 20:44:02.633 32593-931/org.mydev.app.debug E/UncaughtException: java.lang.NullPointerException: Attempt to read from field 'java.lang.Object maps.W.d$c.c' on a null object reference
                                                                                  at maps.W.d.a(Unknown Source)
                                                                                  at maps.W.d.b(Unknown Source)
                                                                                  at maps.X.J.a(Unknown Source)
                                                                                  at maps.ac.i$d.a(Unknown Source)
                                                                                  at maps.ac.i.a(Unknown Source)
                                                                                  at maps.ac.n.a(Unknown Source)
                                                                                  at maps.X.A.a(Unknown Source)
                                                                                  at maps.X.H.a(Unknown Source)
                                                                                  at maps.X.H.b(Unknown Source)
                                                                                  at maps.X.y$f.f(Unknown Source)
                                                                                  at maps.X.y$f.run(Unknown Source)
06-17 20:44:02.673 32593-32593/org.mydev.app.debug I/Choreographer: Skipped 557 frames!  The application may be doing too much work on its main thread.

Try this. 尝试这个。

<activity
        android:windowSoftInputMode="stateHidden"
        android:name=".activity.MainActivity"
        android:configChanges="orientation|screenSize"
        android:hardwareAccelerated="true"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar">

else use this method to hide the Keyboard with respect to EditText. 否则,使用此方法相对于EditText隐藏Keyboard。

public static void hideKeyboadOnView(Context context, View view) {
    InputMethodManager inputManager = (InputMethodManager)
            context.getSystemService(Context.INPUT_METHOD_SERVICE);

    inputManager.hideSoftInputFromWindow(
            view.getWindowToken(), 0);

   /* inputManager.hideSoftInputFromWindow(activity.getCurrentFocus()
                    .getWindowToken(),
            InputMethodManager.HIDE_NOT_ALWAYS);*/
}

and pass the edittext view in this method. 并在此方法中传递edittext视图。

I solved this by adding android:windowSoftInputMode="adjustPan". 我通过添加android:windowSoftInputMode =“ adjustPan”解决了这一问题。 Thank you all for guiding me. 谢谢大家的指导。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM