代码之家  ›  专栏  ›  技术社区  ›  Andrew

取消选择任何轨迹球/轨迹板选择

  •  1
  • Andrew  · 技术社区  · 14 年前

    有没有一种方法可以通过程序取消选择/擦除用户使用轨迹球/轨迹板选择的内容?

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

    1 回复  |  直到 14 年前
        1
  •  0
  •   Mark Storer    14 年前

    透过 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恰好返回空值)…你只需要一个其他活动视图的句柄…如果这是你的代码,那就不太难了,如果不是,那就不难了。

    如果这是您的代码,您似乎可以向按钮的onclickHandler添加一个clearFocus()。

    推荐文章