的clearFocus
方法implementation是否clearFocusInternal
呼叫傳遞true
爲refocus
參數的值。這導致了第一個可聚焦元素的請求重點。所以,一個可能的解決方案可能是通過反射來撥打clearFocusInternal(true, false);
,但我沒有真正檢查。
挖進requestFocus
implementation我發現它檢查了根視圖的DescendantFocusability
。使用我已經建立了一個有效的解決方案:
ViewGroup rootView = (ViewGroup) atxtTag.getRootView();
int dfValue = rootView.getDescendantFocusability();
rootView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
atxtTag.clearFocus();
rootView.setDescendantFocusability(dfValue);
此外,重點清理不隱藏軟鍵盤,所以你可能需要隱藏它,以及:
InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(atxtTag.getWindowToken(), 0);
您需要把焦點放在其他可聚焦的小部件上。 ScrollView不可調焦。 – CommonsWare