我想在我的无障碍服务中针对特定操作清除 editText
的输入焦点。
我获取了具有输入焦点的节点并尝试清除它,但 performAction 总是返回 false:
AccessibilityNodeInfo root = getRootInActiveWindow();
AccessibilityNodeInfo focus = root.findFocus(AccessibilityNodeInfo.FOCUS_INPUT);
if(focus != null){
focus.getText(); //return the text in my input
focus.isFocusable(); //return true
focus.isFocused(); // return true
focus.getActions(); //Return the bitmask that contain the Action_clear_focus
boolean sucess = focus.performAction(AccessibilityNodeInfo.ACTION_CLEAR_FOCUS);
Log.v(TAG, "sucess = " + sucess); //Always return FALSE
}
最佳答案
我不知道对 EditText 的 ACTION_CLEAR_FOCUS 的具体处理。 View.java 中操作的返回值只是 !isFocused()。
如果您也拥有应用程序代码,您可能只需单步执行那里的代码,看看发生了什么。例如,如果应用决定焦点需要位于某处,并将其放回 EditText 上,您可以获得观察到的行为。
关于android - 我想修改 EDITTEXT 的焦点, performAction(AccessibilityNodeInfo.ACTION_CLEAR_FOCUS) 总是在 editText 上返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53966704/