// 获取根布局 (DecorView) View rootView = getWindow().getDecorView(); // 添加全局焦点变化监听器 rootView.getViewTreeObserver().addOnGlobalFocusChangeListener( new ViewTreeObserver.OnGlobalFocusChangeListener() { @Override public void onGlobalFocusChanged(View oldFocus, View newFocus) { // 获取类名,注意处理空指针 String oldName = (oldFocus != null) ? oldFocus.getClass().getSimpleName() : "null"; String newName = (newFocus != null) ? newFocus.getClass().getSimpleName() : "null"; Log.d("GlobalFocus", "焦点从 " + oldName + " 切换到了 " + newName); } } );加在onCreate中