有没有人在Android 5.0上解决键盘隐藏崩溃的问题?我使用相同的代码试用了4.4.2,但它没有发生。
这是我的活动设置:
<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">
这是冻结后的日志
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.
答案 0 :(得分:0)
试试这个。
<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">
否则使用此方法隐藏键盘相对于EditText。
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);*/
}
并传递此方法中的edittext视图。
答案 1 :(得分:0)
我通过添加android解决了这个问题:windowSoftInputMode =&#34; adjustPan&#34;。谢谢大家指导我。