Skip to content Skip to sidebar Skip to footer

How To Identify The State From View.getdrawablestate()

I'm attempting to create a custom Button that changes its shadow attributes (radius, distance, etc.) based on button state (pressed, enabled, etc.) I finally accepted that this can

Solution 1:

I just figured it out on my own by trial and error.

The list contains resource identifiers of the "true" states, and does not contain the identifiers of "false" states. The following code addresses my needs:

// Get the relevant drawable statebooleanstatePressed=false, stateEnabled = false;
int[] states = getDrawableState();
for (int state : states)
{
    if (state == android.R.attr.state_enabled)
        stateEnabled = true;
    elseif (state == android.R.attr.state_pressed)
        statePressed = true;
}

Post a Comment for "How To Identify The State From View.getdrawablestate()"