Android View 的TouchMode

来源:互联网 发布:软件测试管理软件 编辑:程序博客网 时间:2024/05/16 05:52

1.由来:touchmode是区分触摸状态和非触摸状态而设置的。

2.touchMode就是当你点击屏幕(当然是触摸屏)的时候就会被激活,而你点击物理按键的时候则会退出此模式。

3.setFocusableInTocuMode与setFocusable的区别:

先说说focus,这就要说道focusable与touchable这两个概念,当你点击屏幕的时候,如果你点的是一个button,那么这个就是touchable,但是unfocusable。而当你点击edittext的时候则是touchable与focusable的状态。说到这里大家都懂的是什么意思了。处于focusable的时候,一般都会有highlight.


在View中源码有一段解释,很好的说明了问题:

 * When a user is navigating a user interface via directional keys such as a D-pad, it is
 * necessary to give focus to actionable items such as buttons so the user can see
 * what will take input.  If the device has touch capabilities, however, and the user
 * begins interacting with the interface by touching it, it is no longer necessary to
 * always highlight, or give focus to, a particular view.  This motivates a mode
 * for interaction named 'touch mode'.
 * </p>
 * <p>
 * For a touch capable device, once the user touches the screen, the device
 * will enter touch mode.  From this point onward, only views for which
 * {@link #isFocusableInTouchMode} is true will be focusable, such as text editing widgets.
 * Other views that are touchable, like buttons, will not take focus when touched; they will
 * only fire the on click listeners.


 * Any time a user hits a directional key, such as a D-pad direction, the view device will
 * exit touch mode, and find a view to take focus, so that the user may resume interacting
 * with the user interface without touching the screen again.



上面的英文说的很清楚,就不做过多解释了。

0 0
原创粉丝点击