android:聚焦,启用,按下和选择状态之间有什么区别?

Eng*_*ici 40 android view

我查看了http://developer.android.com/reference/android/view/View.html以找出差异,但无法理解.我只是部分理解"选定"状态.

有人可以用一些可靠的例子解释这些差异吗?我希望我的问题不是很模糊.如果是的话,如果有人帮我改进它会很棒,因为我不知道如何更清楚地问它.

先感谢您.

500*_*865 43

启用 - >可以进行用户交互.

已禁用 - >无法进行用户交互.

  • 如果您将鼠标悬停在窗口小部件上,它将被聚焦
  • 如果您在该窗口小部件上按下(半按),则会按下该窗口小部件
  • 如果在鼠标位于同一位置时按下并按下,则会选中

  • 谢谢你的澄清!我仍然不清楚焦点:焦点状态如何在触摸屏中工作?它是这样的:当我在屏幕上移动我的手指时,无论我的手指在任何特定时刻,屏幕的那一部分都有焦点? (2认同)

Leo*_*Leo 7

聚焦 - (Window,View)是键盘事件的目的地(是的,一些Androids有物理键盘),有些还有"除臭球"生成左下箭头键盘快捷键.

已激活 - 已激活的窗口小部件(视图).例如,在多选列表中,激活所选视图.我认为API 11中这个附加阶段的必要性是由于激活了包含复选框的多选.因此,需要分离所选和检查的状态.

已选中 - 仅适用于复选框和其他可选视图.

视图状态的完整列表是(左侧的StateSet id,右侧的标志):

    R.attr.state_window_focused,    VIEW_STATE_WINDOW_FOCUSED,
    R.attr.state_selected,          VIEW_STATE_SELECTED,
    R.attr.state_focused,           VIEW_STATE_FOCUSED,
    R.attr.state_enabled,           VIEW_STATE_ENABLED,
    R.attr.state_pressed,           VIEW_STATE_PRESSED,
    R.attr.state_activated,         VIEW_STATE_ACTIVATED,
    R.attr.state_accelerated,       VIEW_STATE_ACCELERATED,
    R.attr.state_hovered,           VIEW_STATE_HOVERED,
    R.attr.state_drag_can_accept,   VIEW_STATE_DRAG_CAN_ACCEPT,
    R.attr.state_drag_hovered,      VIEW_STATE_DRAG_HOVERED
Run Code Online (Sandbox Code Playgroud)

另见:

/**
 * Changes the activated state of this view. A view can be activated or not.
 * Note that activation is not the same as selection.  Selection is
 * a transient property, representing the view (hierarchy) the user is
 * currently interacting with.  Activation is a longer-term state that the
 * user can move views in and out of.  For example, in a list view with
 * single or multiple selection enabled, the views in the current selection
 * set are activated.  (Um, yeah, we are deeply sorry about the terminology
 * here.)  The activated state is propagated down to children of the view it
 * is set on.
 *
 * @param activated true if the view must be activated, false otherwise
 */
public void setActivated(boolean activated)



/**
 * Dispatch a key event to the next view on the focus path. This path runs
 * from the top of the view tree down to the currently focused view. If this
 * view has focus, it will dispatch to itself. Otherwise it will dispatch
 * the next node down the focus path. This method also fires any key
 * listeners.
 *
 * @param event The key event to be dispatched.
 * @return True if the event was handled, false otherwise.
 */
public boolean dispatchKeyEvent(KeyEvent event)
Run Code Online (Sandbox Code Playgroud)