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;
}
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;
}
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);
}
}
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;
}
}
}
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));
}
Aggregations