recyclerview填充数据后会自动获取焦点,填充数据后在设置移除焦点,才能有效移除recyclerView的焦点;
然后再把焦点设置到其他的view上去,我这边是两个view在不同的fragment里,所以用了eventbus去通知设置焦点
public static final String NOTIFY_HOME_GET_FOCUS = "NOTIFY_HOME_GET_FOCUS";
fragment2代码片段:
recyclerView.setFocusable(false); recyclerView.clearFocus(); EventBus.getDefault().post(NOTIFY_HOME_GET_FOCUS);
fragment1代码片段:
@Subscribe(threadMode = ThreadMode.MAIN) public void notifygetFoucs(String s){ if (s.equals(NOTIFY_HOME_GET_FOCUS)){ tabLayout.setFocusable(true); tabLayout.setFocusableInTouchMode(true); tabLayout.requestFocus(); tabLayout.requestFocusFromTouch(); } }
ok,成功。