private void update() {
StateListDrawable background = new StateListDrawable();
background.addState(new int[]{android.R.attr.state_pressed}, createDrawable(backgroundColorPressed, cornerColorPressed, cornerWidth, cornerRadius));
background.addState(new int[]{-android.R.attr.state_enabled}, createDrawable(backgroundColorDisabled, cornerColorDisabled, cornerWidth, cornerRadius));
background.addState(StateSet.WILD_CARD, createDrawable(backgroundColor, cornerColor, cornerWidth, cornerRadius));
setBackground(background);
setTextColor(new ColorStateList(
new int[][]{
new int[]{android.R.attr.state_pressed},
new int[]{-android.R.attr.state_enabled},
new int[]{}
},
new int[]{
textColorPressed,
textColorDisabled,
textColor
}
));
}
java类android.graphics.drawable.StateListDrawable的实例源码
RoundButton.java 文件源码
项目:RoundButton
阅读 35
收藏 0
点赞 0
评论 0
Label.java 文件源码
项目:Toodoo
阅读 38
收藏 0
点赞 0
评论 0
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[]{android.R.attr.state_pressed}, createRectDrawable(mColorPressed));
drawable.addState(new int[]{}, createRectDrawable(mColorNormal));
if (Util.hasLollipop()) {
RippleDrawable ripple = new RippleDrawable(new ColorStateList(new int[][]{{}},
new int[]{mColorRipple}), drawable, null);
setOutlineProvider(new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, view.getWidth(), view.getHeight());
}
});
setClipToOutline(true);
mBackgroundDrawable = ripple;
return ripple;
}
mBackgroundDrawable = drawable;
return drawable;
}
ButtonRoundCorner.java 文件源码
项目:SunmiUI
阅读 29
收藏 0
点赞 0
评论 0
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void setBackgroundColor(int colorPressed, int colorNormal){
StateListDrawable sd = new StateListDrawable();
int[] state_pressed = new int[]{android.R.attr.state_pressed};
int[] state_normal = new int[]{android.R.attr.state_enabled};
GradientDrawable pressed = new GradientDrawable();
pressed.setColor(colorPressed);
pressed.setCornerRadius(10);
GradientDrawable enable = new GradientDrawable();
enable.setColor(colorNormal);
enable.setCornerRadius(10);
sd.addState(state_pressed, pressed);
sd.addState(state_normal, enable);
bg.setBackground(sd);
}
Label.java 文件源码
项目:Toodoo
阅读 52
收藏 0
点赞 0
评论 0
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionDown() {
if (mUsingStyle) {
mBackgroundDrawable = getBackground();
}
if (mBackgroundDrawable instanceof StateListDrawable) {
StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
drawable.setState(new int[]{android.R.attr.state_pressed});
} else if (Util.hasLollipop() && mBackgroundDrawable instanceof RippleDrawable) {
RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
ripple.setState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed});
ripple.setHotspot(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
ripple.setVisible(true, true);
}
// setPressed(true);
}
DrawableUtil.java 文件源码
项目:LuaViewPlayground
阅读 33
收藏 0
点赞 0
评论 0
/**
* create state list drawable
*
* @param context
* @param idNormal
* @param idPressed
* @param idFocused
* @param idUnable
* @return
*/
public static StateListDrawable createStateListDrawable(Context context, int idNormal, int idPressed, int idFocused, int idUnable) {
StateListDrawable bg = new StateListDrawable();
Drawable normal = idNormal == -1 ? null : context.getResources().getDrawable(idNormal);
Drawable pressed = idPressed == -1 ? null : context.getResources().getDrawable(idPressed);
Drawable focused = idFocused == -1 ? null : context.getResources().getDrawable(idFocused);
Drawable unable = idUnable == -1 ? null : context.getResources().getDrawable(idUnable);
// View.PRESSED_ENABLED_STATE_SET
bg.addState(new int[]{android.R.attr.state_pressed, android.R.attr.state_enabled}, pressed);
// View.ENABLED_FOCUSED_STATE_SET
bg.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_focused}, focused);
// View.ENABLED_STATE_SET
bg.addState(new int[]{android.R.attr.state_enabled}, normal);
// View.FOCUSED_STATE_SET
bg.addState(new int[]{android.R.attr.state_focused}, focused);
// View.WINDOW_FOCUSED_STATE_SET
bg.addState(new int[]{android.R.attr.state_window_focused}, unable);
// View.EMPTY_STATE_SET
bg.addState(new int[]{}, normal);
return bg;
}
Util.java 文件源码
项目:OpenEyesReading-android
阅读 34
收藏 0
点赞 0
评论 0
public void setCircleButtonStateListDrawable(View circleButton, int radius,int color) {
WeakReference<Bitmap> imageNormal = new WeakReference<>(Bitmap.createBitmap(2 * radius, 2 * radius, Bitmap.Config.ARGB_8888));
Canvas canvasNormal = new Canvas(imageNormal.get());
Paint paintNormal = new Paint();
paintNormal.setAntiAlias(true);
paintNormal.setColor(color);
canvasNormal.drawCircle(radius, radius, radius, paintNormal);
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(StateSet.WILD_CARD, new BitmapDrawable(circleButton.getContext().getResources(), imageNormal.get()));
if (android.os.Build.VERSION.SDK_INT >= 16) {
circleButton.setBackground(stateListDrawable);
} else {
circleButton.setBackgroundDrawable(stateListDrawable);
}
}
ResUtil.java 文件源码
项目:RLibrary
阅读 33
收藏 0
点赞 0
评论 0
/**
* Generate bg drawable drawable.
*
* @param radii the radii
* @param pressColor the press color
* @param defaultColor the default color
* @return the drawable
*/
public static Drawable generateRoundDrawable(Resources res, float radii, int pressColor, int defaultColor) {
radii = dpToPx(res, radii);
//外环的圆角矩形
float[] outRadii = new float[]{radii, radii, radii, radii, radii, radii, radii, radii};//四个角的 圆角幅度,8个可以设置的值,每个角都有2个边 2*4=8个
//按下状态
Shape roundRectShape = new RoundRectShape(outRadii, null, null);//圆角背景
ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圆角shape
shopDrawablePress.getPaint().setColor(pressColor);//设置颜色
//正常状态
Shape roundRectShapeNormal = new RoundRectShape(outRadii, null, null);
ShapeDrawable shopDrawableNormal = new ShapeDrawable(roundRectShapeNormal);
shopDrawableNormal.getPaint().setColor(defaultColor);
StateListDrawable bgStateDrawable = new StateListDrawable();//状态shape
bgStateDrawable.addState(new int[]{android.R.attr.state_pressed}, shopDrawablePress);//按下状态
bgStateDrawable.addState(new int[]{}, shopDrawableNormal);//其他状态
return bgStateDrawable;
}
ResUtil.java 文件源码
项目:RLibrary
阅读 34
收藏 0
点赞 0
评论 0
/**
* 正常 圆角边框;
* 按下 圆角色块
*/
public static Drawable generateBorderDrawable(float radii, float borderWidth, int pressColor, int defaultColor) {
//外环的圆角矩形
float[] outRadii = new float[]{radii, radii, radii, radii, radii, radii, radii, radii};//四个角的 圆角幅度,8个可以设置的值,每个角都有2个边 2*4=8个
RectF inset = new RectF(borderWidth, borderWidth, borderWidth, borderWidth);
//按下状态
Shape roundRectShape = new RoundRectShape(outRadii, null, null);//圆角背景
ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圆角shape
shopDrawablePress.getPaint().setColor(pressColor);//设置颜色
//正常状态
Shape roundRectShapeNormal = new RoundRectShape(outRadii, inset, outRadii);
ShapeDrawable shopDrawableNormal = new ShapeDrawable(roundRectShapeNormal);
shopDrawableNormal.getPaint().setColor(defaultColor);
StateListDrawable bgStateDrawable = new StateListDrawable();//状态shape
bgStateDrawable.addState(new int[]{android.R.attr.state_pressed}, shopDrawablePress);//按下状态
bgStateDrawable.addState(new int[]{}, shopDrawableNormal);//其他状态
return bgStateDrawable;
}
YearPickerView.java 文件源码
项目:boohee_v5.6
阅读 39
收藏 0
点赞 0
评论 0
public YearPickerView(Context context, DatePickerController controller) {
super(context);
this.mController = controller;
this.mController.registerOnDateChangedListener(this);
setLayoutParams(new LayoutParams(-1, -2));
Resources res = context.getResources();
this.mViewSize = res.getDimensionPixelOffset(R.dimen.mdtp_date_picker_view_animator_height);
this.mChildSize = res.getDimensionPixelOffset(R.dimen.mdtp_year_label_height);
setVerticalFadingEdgeEnabled(true);
setFadingEdgeLength(this.mChildSize / 3);
init(context);
setOnItemClickListener(this);
setSelector(new StateListDrawable());
setDividerHeight(0);
onDateChanged();
}
BitmapUtil.java 文件源码
项目:AppCommonFrame
阅读 38
收藏 0
点赞 0
评论 0
/**
* 通过代码配置一个selector XML对象 . <br>
* @author liulongzhenhai 2012-7-4 上午10:45:03 <br>
* @param normal 没有状态
* @param pressed 按下状态
* @param focused 获取焦点状态
* @param unable 无状态
* @return 返回selector 的对象布局
*/
public static StateListDrawable getNewSelector(final Drawable normal, final Drawable pressed,
final Drawable focused, final Drawable unable) {
final StateListDrawable bg = new StateListDrawable();
// View.PRESSED_ENABLED_STATE_SET
bg.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }, pressed);
// View.ENABLED_FOCUSED_STATE_SET
bg.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_focused }, focused);
// View.ENABLED_STATE_SET
bg.addState(new int[] { android.R.attr.state_enabled }, normal);
// View.FOCUSED_STATE_SET
bg.addState(new int[] { android.R.attr.state_focused }, focused);
// View.WINDOW_FOCUSED_STATE_SET
bg.addState(new int[] { android.R.attr.state_window_focused }, unable);
// View.EMPTY_STATE_SET
bg.addState(new int[] {}, normal);
return bg;
}
FloatingActionButton.java 文件源码
项目:editor-sql
阅读 35
收藏 0
点赞 0
评论 0
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[]{-android.R.attr.state_enabled}, createCircleDrawable(mColorDisabled));
drawable.addState(new int[]{android.R.attr.state_pressed}, createCircleDrawable(mColorPressed));
drawable.addState(new int[]{}, createCircleDrawable(mColorNormal));
if (Util.hasLollipop()) {
RippleDrawable ripple = new RippleDrawable(new ColorStateList(new int[][]{{}},
new int[]{mColorRipple}), drawable, null);
setOutlineProvider(new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, view.getWidth(), view.getHeight());
}
});
setClipToOutline(true);
mBackgroundDrawable = ripple;
return ripple;
}
mBackgroundDrawable = drawable;
return drawable;
}
Label.java 文件源码
项目:editor-sql
阅读 35
收藏 0
点赞 0
评论 0
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[]{android.R.attr.state_pressed}, createRectDrawable(mColorPressed));
drawable.addState(new int[]{}, createRectDrawable(mColorNormal));
if (Util.hasLollipop()) {
RippleDrawable ripple = new RippleDrawable(new ColorStateList(new int[][]{{}},
new int[]{mColorRipple}), drawable, null);
setOutlineProvider(new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, view.getWidth(), view.getHeight());
}
});
setClipToOutline(true);
mBackgroundDrawable = ripple;
return ripple;
}
mBackgroundDrawable = drawable;
return drawable;
}
CircularProgressButton.java 文件源码
项目:SmartOrnament
阅读 37
收藏 0
点赞 0
评论 0
private void initIdleStateDrawable() {
int colorNormal = getNormalColor(mIdleColorState);
int colorPressed = getPressedColor(mIdleColorState);
int colorFocused = getFocusedColor(mIdleColorState);
int colorDisabled = getDisabledColor(mIdleColorState);
if (background == null) {
background = createDrawable(colorNormal);
}
StrokeGradientDrawable drawableDisabled = createDrawable(colorDisabled);
StrokeGradientDrawable drawableFocused = createDrawable(colorFocused);
StrokeGradientDrawable drawablePressed = createDrawable(colorPressed);
mIdleStateDrawable = new StateListDrawable();
mIdleStateDrawable.addState(new int[]{android.R.attr.state_pressed}, drawablePressed.getGradientDrawable());
mIdleStateDrawable.addState(new int[]{android.R.attr.state_focused}, drawableFocused.getGradientDrawable());
mIdleStateDrawable.addState(new int[]{-android.R.attr.state_enabled}, drawableDisabled.getGradientDrawable());
mIdleStateDrawable.addState(StateSet.WILD_CARD, background.getGradientDrawable());
}
Label.java 文件源码
项目:MDWechat
阅读 50
收藏 0
点赞 0
评论 0
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[]{android.R.attr.state_pressed}, createRectDrawable(mColorPressed));
drawable.addState(new int[]{}, createRectDrawable(mColorNormal));
if (Util.hasLollipop()) {
RippleDrawable ripple = new RippleDrawable(new ColorStateList(new int[][]{{}},
new int[]{mColorRipple}), drawable, null);
setOutlineProvider(new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, view.getWidth(), view.getHeight());
}
});
setClipToOutline(true);
mBackgroundDrawable = ripple;
return ripple;
}
mBackgroundDrawable = drawable;
return drawable;
}
Label.java 文件源码
项目:MDWechat
阅读 44
收藏 0
点赞 0
评论 0
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionDown() {
if (mUsingStyle) {
mBackgroundDrawable = getBackground();
}
if (mBackgroundDrawable instanceof StateListDrawable) {
StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
drawable.setState(new int[]{android.R.attr.state_pressed});
} else if (Util.hasLollipop() && mBackgroundDrawable instanceof RippleDrawable) {
RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
ripple.setState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed});
ripple.setHotspot(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
ripple.setVisible(true, true);
}
// setPressed(true);
}
Label.java 文件源码
项目:MDWechat
阅读 44
收藏 0
点赞 0
评论 0
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionUp() {
if (mUsingStyle) {
mBackgroundDrawable = getBackground();
}
if (mBackgroundDrawable instanceof StateListDrawable) {
StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
drawable.setState(new int[]{});
} else if (Util.hasLollipop() && mBackgroundDrawable instanceof RippleDrawable) {
RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
ripple.setState(new int[]{});
ripple.setHotspot(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
ripple.setVisible(true, true);
}
// setPressed(false);
}
ColoringTest.java 文件源码
项目:silly-android
阅读 41
收藏 0
点赞 0
评论 0
/**
* Tests the {@link Coloring#createMultiStateDrawable(Drawable, Drawable, Drawable, boolean)} method.
* <p>
* Unfortunately some Drawable properties are not shadowed by Robolectric yet, so we can test only the basic stuff here.
*/
@Test
public final void testCreateMultiStateDrawable() {
// noinspection deprecation - can't enforce Lollipop here
final BitmapDrawable normal = (BitmapDrawable) mActivityContext.getResources().getDrawable(android.R.drawable.btn_star_big_on);
assertNotNull("Normal drawable is null", normal);
// noinspection deprecation - can't enforce Lollipop here
final BitmapDrawable clicked = (BitmapDrawable) mActivityContext.getResources().getDrawable(android.R.drawable.btn_star_big_off);
assertNotNull("Clicked drawable is null", clicked);
// noinspection deprecation - can't enforce Lollipop here
final BitmapDrawable checked = (BitmapDrawable) mActivityContext.getResources().getDrawable(android.R.drawable.star_off);
assertNotNull("Checked drawable is null", checked);
final StateListDrawable stateList = Coloring.createMultiStateDrawable(normal, clicked, checked, true);
assertNotNull("Contrast state drawable is null", stateList);
assertTrue("Contrast state drawable is not stateful", stateList.isStateful());
final Drawable.ConstantState constantState = stateList.getConstantState();
assertNotNull("Constant state is null", constantState);
}
BadgeDrawableBuilder.java 文件源码
项目:android-paypal-example
阅读 45
收藏 0
点赞 0
评论 0
public StateListDrawable build(Context ctx) {
StateListDrawable stateListDrawable = new StateListDrawable();
GradientDrawable normal = (GradientDrawable) ContextCompat.getDrawable(ctx, R.drawable.action_item_badge);
GradientDrawable selected = (GradientDrawable) normal.getConstantState().newDrawable().mutate();
normal.setColor(mColor);
selected.setColor(mColorPressed);
if (mStroke > -1) {
normal.setStroke(mStroke, mStrokeColor);
selected.setStroke(mStroke, mStrokeColor);
}
if (mCorners > -1) {
normal.setCornerRadius(mCorners);
selected.setCornerRadius(mCorners);
}
stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, selected);
stateListDrawable.addState(StateSet.WILD_CARD, normal);
return stateListDrawable;
}
ThemeUtils.java 文件源码
项目:Mix
阅读 35
收藏 0
点赞 0
评论 0
public static boolean containsNinePatch(Drawable drawable) {
drawable = getWrapperDrawable(drawable);
if (drawable instanceof NinePatchDrawable
|| drawable instanceof InsetDrawable
|| drawable instanceof LayerDrawable) {
return true;
} else if (drawable instanceof StateListDrawable) {
final DrawableContainer.DrawableContainerState containerState = ((DrawableContainer.DrawableContainerState) drawable.getConstantState());
//can't getBaseApplication containState from drawable which is containing DrawableWrapperDonut
//https://code.google.com/p/android/issues/detail?id=169920
if (containerState == null) {
return true;
}
for (Drawable dr : containerState.getChildren()) {
dr = getWrapperDrawable(dr);
if (dr instanceof NinePatchDrawable
|| dr instanceof InsetDrawable
|| dr instanceof LayerDrawable) {
return true;
}
}
}
return false;
}
CustomResourceMgmt.java 文件源码
项目:letv
阅读 29
收藏 0
点赞 0
评论 0
public Drawable getCheckStatusDrawable(String origin, String checked, String pressed, String checkpressed, boolean is9Png) {
int originId = this.mResources.getIdentifier(origin, "drawable", this.packageName);
int selectId = this.mResources.getIdentifier(checked, "drawable", this.packageName);
int pressedId = this.mResources.getIdentifier(pressed, "drawable", this.packageName);
int selectpressId = this.mResources.getIdentifier(checkpressed, "drawable", this.packageName);
if (originId == 0 && selectId == 0 && pressedId == 0 && selectpressId == 0) {
String suffix = (is9Png ? ".9" : "") + ".png";
return new StateListDrawableBuilder(this.mContext, "drawable/" + origin + suffix).setPressDrawable("drawable/" + pressed + suffix).setCheckedDrawable("drawable/" + checked + suffix).setPressCheckedDrawable("drawable/" + checkpressed + suffix).create();
}
Drawable mStateListDrawable = new StateListDrawable();
mStateListDrawable.addState(new int[]{16842912}, this.mResources.getDrawable(selectId));
mStateListDrawable.addState(new int[]{16842919}, this.mResources.getDrawable(pressedId));
mStateListDrawable.addState(new int[]{16842919, 16842912}, this.mResources.getDrawable(selectpressId));
mStateListDrawable.addState(new int[0], this.mResources.getDrawable(originId));
return mStateListDrawable;
}
EmojiTabLayout.java 文件源码
项目:RLibrary
阅读 35
收藏 0
点赞 0
评论 0
public void addItem(@DrawableRes int ico) {
EmojiTabItemView itemView = new EmojiTabItemView(getContext());
itemView.setImageResource(ico);
if (mItemBackgroundRes == 0) {
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[]{android.R.attr.state_checked},
new ColorDrawable(getResources().getColor(R.color.default_base_bg_press)));
stateListDrawable.addState(new int[]{android.R.attr.state_pressed},
new ColorDrawable(getResources().getColor(R.color.default_base_bg_press)));
stateListDrawable.addState(new int[]{}, new ColorDrawable(Color.TRANSPARENT));
itemView.setBackground(stateListDrawable);
} else {
itemView.setBackgroundResource(mItemBackgroundRes);
}
addView(itemView, -1, -1);
itemView.setOnClickListener(this);
}
Label.java 文件源码
项目:ChatExchange-old
阅读 45
收藏 0
点赞 0
评论 0
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[]{android.R.attr.state_pressed}, createRectDrawable(mColorPressed));
drawable.addState(new int[]{}, createRectDrawable(mColorNormal));
if (Util.hasLollipop()) {
RippleDrawable ripple = new RippleDrawable(new ColorStateList(new int[][]{{}},
new int[]{mColorRipple}), drawable, null);
setOutlineProvider(new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, view.getWidth(), view.getHeight());
}
});
setClipToOutline(true);
mBackgroundDrawable = ripple;
return ripple;
}
mBackgroundDrawable = drawable;
return drawable;
}
ResUtil.java 文件源码
项目:RLibrary
阅读 35
收藏 0
点赞 0
评论 0
/**
* Generate bg drawable drawable.
*
* @param pressColor the press color
* @param defaultColor the default color
* @return the drawable
*/
public static Drawable generateRoundDrawable(float radii, int pressColor, int defaultColor) {
//圆角
Shape roundRectShape = new RoundRectShape(new float[]{radii, radii, radii, radii, radii, radii, radii, radii}, null, null);//圆角背景
//按下状态
ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圆角shape
shopDrawablePress.getPaint().setColor(pressColor);//设置颜色
//正常状态
ShapeDrawable shopDrawableNormal = new ShapeDrawable(roundRectShape);
shopDrawableNormal.getPaint().setColor(defaultColor);
StateListDrawable bgStateDrawable = new StateListDrawable();//状态shape
bgStateDrawable.addState(new int[]{android.R.attr.state_pressed}, shopDrawablePress);//按下状态
bgStateDrawable.addState(new int[]{-android.R.attr.state_enabled}, shopDrawablePress);
bgStateDrawable.addState(new int[]{}, shopDrawableNormal);//其他状态
return bgStateDrawable;
}
Label.java 文件源码
项目:ChatExchange-old
阅读 33
收藏 0
点赞 0
评论 0
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionUp() {
if (mUsingStyle) {
mBackgroundDrawable = getBackground();
}
if (mBackgroundDrawable instanceof StateListDrawable) {
StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
drawable.setState(new int[]{});
} else if (Util.hasLollipop() && mBackgroundDrawable instanceof RippleDrawable) {
RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
ripple.setState(new int[]{});
ripple.setHotspot(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
ripple.setVisible(true, true);
}
// setPressed(false);
}
MediaActivity.java 文件源码
项目:Watermark
阅读 33
收藏 0
点赞 0
评论 0
private StateListDrawable createDefaultOverButtonBgDrawable() {
int dp12 = (int) ThemeUtils.applyDimensionDp(this, 12.f);
int dp8 = (int) ThemeUtils.applyDimensionDp(this, 8.f);
float dp4 = ThemeUtils.applyDimensionDp(this, 4.f);
float[] round = new float[]{dp4, dp4, dp4, dp4, dp4, dp4, dp4, dp4};
ShapeDrawable pressedDrawable = new ShapeDrawable(new RoundRectShape(round, null, null));
pressedDrawable.setPadding(dp12, dp8, dp12, dp8);
int pressedColor = ThemeUtils.resolveColor(this, R.attr.gallery_toolbar_over_button_pressed_color, R.color.gallery_default_toolbar_over_button_pressed_color);
pressedDrawable.getPaint().setColor(pressedColor);
int normalColor = ThemeUtils.resolveColor(this, R.attr.gallery_toolbar_over_button_normal_color, R.color.gallery_default_toolbar_over_button_normal_color);
ShapeDrawable normalDrawable = new ShapeDrawable(new RoundRectShape(round, null, null));
normalDrawable.setPadding(dp12, dp8, dp12, dp8);
normalDrawable.getPaint().setColor(normalColor);
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, pressedDrawable);
stateListDrawable.addState(new int[]{}, normalDrawable);
return stateListDrawable;
}
SafetyKeyboard.java 文件源码
项目:PWEditText-SafeKeyboard
阅读 40
收藏 0
点赞 0
评论 0
private StateListDrawable getDrawableSeletor(Drawable normal,
Drawable press) {
StateListDrawable bg = new StateListDrawable();
if (null != normal) {
bg.addState(new int[] { android.R.attr.state_pressed }, press);
}
if (null != press) {
bg.addState(new int[] { android.R.attr.state_enabled }, normal);
}
return bg;
}
ScanActivity.java 文件源码
项目:MeetMusic
阅读 38
收藏 0
点赞 0
评论 0
private void setScanBtnBg(){
int defColor = CustomAttrValueUtil.getAttrColorValue(R.attr.colorAccent,R.color.colorAccent,this);
int pressColor = CustomAttrValueUtil.getAttrColorValue(R.attr.press_color,R.color.colorAccent,this);
Drawable backgroundDrawable = scanBtn.getBackground();
StateListDrawable sld = (StateListDrawable) backgroundDrawable;// 通过向下转型,转回原型,selector对应的Java类为:StateListDrawable
SelectorUtil.changeViewColor(sld,new int[]{pressColor,defColor});
}
DrawableUtils.java 文件源码
项目:GitHub
阅读 40
收藏 0
点赞 0
评论 0
private static StateListDrawable getStateListDrawable(@ColorInt int normalColor,
@ColorInt int pressedColor) {
StateListDrawable states = new StateListDrawable();
states.addState(new int[]{android.R.attr.state_activated}, getColorDrawable(pressedColor));
states.addState(new int[]{}, getColorDrawable(normalColor));
// Animating across states.
// It seems item background is lost on scrolling out of the screen, 21 <= API <= 23
if (!Utils.hasLollipop() || Utils.hasNougat()) {
int duration = 200; //android.R.integer.config_shortAnimTime
states.setEnterFadeDuration(duration);
states.setExitFadeDuration(duration);
}
return states;
}
ResHelper.java 文件源码
项目:SingleSelectBar
阅读 48
收藏 0
点赞 0
评论 0
private Drawable getPressedEffectBeforeLollipop(CORNER_POSITION cornerPosition, int color) {
ShapeDrawable colorDrawablePressed = getCornerStateDrawable(cornerPosition);
colorDrawablePressed.getPaint().setColor(color);
colorDrawablePressed.getPaint().setStyle(Paint.Style.FILL);
colorDrawablePressed.getPaint().setAlpha(PRESSED_ALPHA_VALUE);
colorDrawablePressed.mutate();
StateListDrawable textBgDrawable = new StateListDrawable();
textBgDrawable.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed}, colorDrawablePressed);
return textBgDrawable;
}
FastAdapterUIUtils.java 文件源码
项目:GitHub
阅读 43
收藏 0
点赞 0
评论 0
/**
* helper to create an StateListDrawable for the given normal and pressed color
*
* @param normalColor the normal color
* @param pressedColor the pressed color
* @return the StateListDrawable
*/
private static StateListDrawable getStateListDrawable(
int normalColor, int pressedColor) {
StateListDrawable states = new StateListDrawable();
states.addState(new int[]{android.R.attr.state_pressed},
new ColorDrawable(pressedColor));
states.addState(new int[]{android.R.attr.state_focused},
new ColorDrawable(pressedColor));
states.addState(new int[]{android.R.attr.state_activated},
new ColorDrawable(pressedColor));
states.addState(new int[]{},
new ColorDrawable(normalColor));
return states;
}