android: what is the difference between focused, enabled, pressed, and selected states?

后端 未结 2 1860
天命终不由人
天命终不由人 2020-12-02 14:22

I looked at http://developer.android.com/reference/android/view/View.html to figure out the differences but could not understand much. I only partly understood the \"selecte

相关标签:
2条回答
  • 2020-12-02 15:02

    Enabled -> User Interaction possible.

    Disabled -> User interaction not possible.

    • if you hover the mouse over a widget, it is focussed
    • If you make a press-down (half click) on that widget, it is pressed
    • If you press-down and press-up while the mouse is at the same position, it is selected
    0 讨论(0)
  • 2020-12-02 15:07

    Focused - (Window, View) is a destination of keyboard events (yes, some Androids have physical keyboard) and some have "deodorant-ball" generating left up right down arrows keyboard shortcuts.

    Activated - the widget (view) which is activated. E.g. in multi selection list the selected views are activated. I believe the necessity of this additional stage in API 11 was due to activating multi-selection that contains checkboxes. Thus the selected and checked states need to be separated.

    Selected - is only applicable to check boxes and other selectable views.

    The complete list of View states is (StateSet id on the left, flag on the right):

        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
    

    Also see:

    /**
     * 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)
    
    0 讨论(0)
提交回复
热议问题