Search in sources :

Example 41 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project LshUtils by SenhLinsh.

the class LshXmlCreater method createEnabledSelector.

/**
     * 生成背景选择器
     */
public static StateListDrawable createEnabledSelector(Drawable enabledDrawable, Drawable disabledDrawable) {
    StateListDrawable stateListDrawable = new StateListDrawable();
    stateListDrawable.addState(new int[] { android.R.attr.state_enabled }, enabledDrawable);
    stateListDrawable.addState(new int[] {}, disabledDrawable);
    return stateListDrawable;
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 42 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project LshUtils by SenhLinsh.

the class LshXmlCreater method createPressedSelector.

/**
     * 生成背景选择器
     */
public static StateListDrawable createPressedSelector(Drawable pressedDrawable, Drawable normalDrawable) {
    StateListDrawable stateListDrawable = new StateListDrawable();
    stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, pressedDrawable);
    stateListDrawable.addState(new int[] {}, normalDrawable);
    return stateListDrawable;
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 43 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project LshUtils by SenhLinsh.

the class CountDownView method setColor.

private void setColor() {
    // 设置字体颜色
    setTextColor(LshXmlCreater.createEnabledColorSelector(enabledColor, disabledColor));
    // 设置背景
    Drawable enabledDrawable = LshXmlCreater.createRectangleBorder(roundRadius, strokeWidth, enabledColor);
    Drawable disabledDrawable = LshXmlCreater.createRectangleBorder(roundRadius, strokeWidth, disabledColor);
    StateListDrawable background = LshXmlCreater.createEnabledSelector(enabledDrawable, disabledDrawable);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        setBackground(background);
    } else {
        setBackgroundDrawable(background);
    }
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 44 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project android_frameworks_base by ResurrectionRemix.

the class PopupWindow method setBackgroundDrawable.

/**
     * Specifies the background drawable for this popup window. The background
     * can be set to {@code null}.
     *
     * @param background the popup's background
     * @see #getBackground()
     * @attr ref android.R.styleable#PopupWindow_popupBackground
     */
public void setBackgroundDrawable(Drawable background) {
    mBackground = background;
    // at least one other drawable, intended for the 'below-anchor state'.
    if (mBackground instanceof StateListDrawable) {
        StateListDrawable stateList = (StateListDrawable) mBackground;
        // Find the above-anchor view - this one's easy, it should be labeled as such.
        int aboveAnchorStateIndex = stateList.getStateDrawableIndex(ABOVE_ANCHOR_STATE_SET);
        // Now, for the below-anchor view, look for any other drawable specified in the
        // StateListDrawable which is not for the above-anchor state and use that.
        int count = stateList.getStateCount();
        int belowAnchorStateIndex = -1;
        for (int i = 0; i < count; i++) {
            if (i != aboveAnchorStateIndex) {
                belowAnchorStateIndex = i;
                break;
            }
        }
        // to null so that we'll just use refreshDrawableState.
        if (aboveAnchorStateIndex != -1 && belowAnchorStateIndex != -1) {
            mAboveAnchorBackgroundDrawable = stateList.getStateDrawable(aboveAnchorStateIndex);
            mBelowAnchorBackgroundDrawable = stateList.getStateDrawable(belowAnchorStateIndex);
        } else {
            mBelowAnchorBackgroundDrawable = null;
            mAboveAnchorBackgroundDrawable = null;
        }
    }
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 45 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project UltimateAndroid by cymcsg.

the class FrameLayoutFeedback method setSelector.

private void setSelector(TypedArray a) {
    touchFeedbackDrawable = new StateListDrawable();
    touchFeedbackDrawable.addState(new int[] { android.R.attr.state_pressed }, getColor(a));
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable)

Aggregations

StateListDrawable (android.graphics.drawable.StateListDrawable)166 Drawable (android.graphics.drawable.Drawable)43 LayerDrawable (android.graphics.drawable.LayerDrawable)24 BitmapDrawable (android.graphics.drawable.BitmapDrawable)21 GradientDrawable (android.graphics.drawable.GradientDrawable)21 ColorDrawable (android.graphics.drawable.ColorDrawable)17 Bitmap (android.graphics.Bitmap)13 TextView (android.widget.TextView)12 ShapeDrawable (android.graphics.drawable.ShapeDrawable)11 View (android.view.View)11 AnimationDrawable (android.graphics.drawable.AnimationDrawable)9 ClipDrawable (android.graphics.drawable.ClipDrawable)9 SuppressLint (android.annotation.SuppressLint)8 ColorStateList (android.content.res.ColorStateList)8 Paint (android.graphics.Paint)8 RippleDrawable (android.graphics.drawable.RippleDrawable)7 TargetApi (android.annotation.TargetApi)6 TypedArray (android.content.res.TypedArray)6 TextPaint (android.text.TextPaint)5 Button (android.widget.Button)5