在Android 7.0中,当我运行adb shell monkey -p com.android.contacts --throttle 300 -v 10000000时,
获取日志显示
java.lang.IllegalStateException:焦点搜索返回了无法获得焦点的视图!
--------- beginning of crash
01-19 15:46:05.169 4677 4677 E AndroidRuntime: FATAL EXCEPTION: main
01-19 15:46:05.169 4677 4677 E AndroidRuntime: Process: com.android.launcher3, PID: 4677
01-19 15:46:05.169 4677 4677 E AndroidRuntime: java.lang.IllegalStateException: focus search returned a view that wasn't able to take focus!
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.widget.TextView.onKeyUp(TextView.java:6413)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.KeyEvent.dispatch(KeyEvent.java:2712)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.View.dispatchKeyEvent(View.java:9960)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1630)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1630)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1630)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at com.android.launcher3.allapps.AllAppsContainerView.dispatchKeyEvent(AllAppsContainerView.java:525)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1630)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at com.android.launcher3.dragndrop.DragLayer.dispatchKeyEvent(DragLayer.java:177)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1630)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1630)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1630)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1630)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at com.android.internal.policy.DecorView.superDispatchKeyEvent(DecorView.java:406)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at com.android.internal.policy.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1798)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.app.Activity.dispatchKeyEvent(Activity.java:3029)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at com.android.launcher3.Launcher.dispatchKeyEvent(Launcher.java:2385)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at com.android.internal.policy.DecorView.dispatchKeyEvent(DecorView.java:320)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4337)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4308)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3859)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3912)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3878)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4005)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3886)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4062)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3859)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3912)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3878)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3886)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3859)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3912)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3878)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4038)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:4199)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2400)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1964)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1955)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2377)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.os.MessageQueue.nativePollOnce(Native Method)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.os.MessageQueue.next(MessageQueue.java:323)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.os.Looper.loop(Looper.java:136)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6125)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
01-19 15:46:05.169 4677 4677 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
01-19 15:46:05.191 2244 3952 W ActivityManager: Force finishing activity com.android.launcher3/.Launcher
以下是源代码的一部分
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
// Determine if the key event was actual text, if so, focus the search bar and then dispatch
// the key normally so that it can process this key event
if (!mSearchBarController.isSearchFieldFocused() &&
event.getAction() == KeyEvent.ACTION_DOWN) {
final int unicodeChar = event.getUnicodeChar();
final boolean isKeyNotWhitespace = unicodeChar > 0 &&
!Character.isWhitespace(unicodeChar) && !Character.isSpaceChar(unicodeChar);
if (isKeyNotWhitespace) {
boolean gotKey = TextKeyListener.getInstance().onKeyDown(this, mSearchQueryBuilder,
event.getKeyCode(), event);
if (gotKey && mSearchQueryBuilder.length() > 0) {
mSearchBarController.focusSearchField();
}
}
}
return super.dispatchKeyEvent(event);
}
<com.android.launcher3.ExtendedEditText
android:id="@+id/search_box_input"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:focusableInTouchMode="true"
android:gravity="center"
android:imeOptions="actionSearch|flagNoExtractUi"
android:inputType="text|textNoSuggestions|textCapWords"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:textColor="#4c4c4c"
android:hint="@string/all_apps_search_bar_hint"
android:textColorHint="@drawable/all_apps_search_hint"
android:textSize="16sp" />
有没有人遇到过这样的问题?它是如何产生的?怎么解决?