1

有没有办法以编程方式取消选择/擦除用户使用轨迹球/触控板选择的任何内容?

当我点击 Activity 上的后退按钮时,它回退到的 Activity 有一个被选中的按钮,就好像用户使用了轨迹球/垫一样。我不确定在上一个 Activity 上选择了什么,但显然是这样。我想在活动结束之前以编程方式擦除任何选择。

4

1 回答 1

0

通过查看 JavaDoc for View,我看到了许多与焦点相关的函数。

void clearFocus(); // drop focus from this view.
View findFocus(); // finds a view that is a child of this view that has focus, if any
View focusSearch(int dir); // finds the next view that can take focus in the given direction
void requestFocus

听起来findFocus().clearFocus()应该可以解决问题(除非 findFocus 碰巧返回 null)...您只需要处理其他活动的 View... .

如果它是您的代码,那么您似乎可以将 clearFocus() 添加到按钮的 onClickHandler 中。

于 2010-11-04T19:34:28.877 回答