当前位置: 首页>>代码示例>>Java>>正文


Java StateListDrawable类代码示例

本文整理汇总了Java中android.graphics.drawable.StateListDrawable的典型用法代码示例。如果您正苦于以下问题:Java StateListDrawable类的具体用法?Java StateListDrawable怎么用?Java StateListDrawable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


StateListDrawable类属于android.graphics.drawable包,在下文中一共展示了StateListDrawable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: update

import android.graphics.drawable.StateListDrawable; //导入依赖的package包/类
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
            }
    ));
}
 
开发者ID:JMaroz,项目名称:RoundButton,代码行数:21,代码来源:RoundButton.java

示例2: createFillDrawable

import android.graphics.drawable.StateListDrawable; //导入依赖的package包/类
@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;
}
 
开发者ID:OlayinkaPeter,项目名称:Toodoo,代码行数:24,代码来源:Label.java

示例3: setBackgroundColor

import android.graphics.drawable.StateListDrawable; //导入依赖的package包/类
@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);
}
 
开发者ID:teisun,项目名称:SunmiUI,代码行数:19,代码来源:ButtonRoundCorner.java

示例4: onActionDown

import android.graphics.drawable.StateListDrawable; //导入依赖的package包/类
@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);
    }
 
开发者ID:OlayinkaPeter,项目名称:Toodoo,代码行数:18,代码来源:Label.java

示例5: createStateListDrawable

import android.graphics.drawable.StateListDrawable; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:31,代码来源:DrawableUtil.java

示例6: setCircleButtonStateListDrawable

import android.graphics.drawable.StateListDrawable; //导入依赖的package包/类
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);
    }

}
 
开发者ID:shenhuanet,项目名称:OpenEyesReading-android,代码行数:17,代码来源:Util.java

示例7: drawableStateChanged

import android.graphics.drawable.StateListDrawable; //导入依赖的package包/类
@Override
protected void drawableStateChanged() {
	super.drawableStateChanged();

	if (!mIsThumbUseDrawable && mThumbColor != null) {
		mCurrThumbColor = mThumbColor.getColorForState(getDrawableState(), mCurrThumbColor);
	} else {
		setDrawableState(mThumbDrawable);
	}

	int[] nextState = isChecked() ? UNCHECKED_PRESSED_STATE : CHECKED_PRESSED_STATE;
	ColorStateList textColors = getTextColors();
	if (textColors != null) {
		int defaultTextColor = textColors.getDefaultColor();
		mOnTextColor = textColors.getColorForState(CHECKED_PRESSED_STATE, defaultTextColor);
		mOffTextColor = textColors.getColorForState(UNCHECKED_PRESSED_STATE, defaultTextColor);
	}
	if (!mIsBackUseDrawable && mBackColor != null) {
		mCurrBackColor = mBackColor.getColorForState(getDrawableState(), mCurrBackColor);
		mNextBackColor = mBackColor.getColorForState(nextState, mCurrBackColor);
	} else {
		if (mBackDrawable instanceof StateListDrawable && mFadeBack) {
			mBackDrawable.setState(nextState);
			mNextBackDrawable = mBackDrawable.getCurrent().mutate();
		} else {
			mNextBackDrawable = null;
		}
		setDrawableState(mBackDrawable);
		if (mBackDrawable != null) {
			mCurrentBackDrawable = mBackDrawable.getCurrent().mutate();
		}
	}
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:34,代码来源:SwitchButton.java

示例8: generateRoundDrawable

import android.graphics.drawable.StateListDrawable; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:32,代码来源:ResUtil.java

示例9: generateBorderDrawable

import android.graphics.drawable.StateListDrawable; //导入依赖的package包/类
/**
 * 正常 圆角边框;
 * 按下 圆角色块
 */
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;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:27,代码来源:ResUtil.java

示例10: YearPickerView

import android.graphics.drawable.StateListDrawable; //导入依赖的package包/类
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();
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:17,代码来源:YearPickerView.java

示例11: getNewSelector

import android.graphics.drawable.StateListDrawable; //导入依赖的package包/类
/**
 * 通过代码配置一个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;
}
 
开发者ID:VK2012,项目名称:AppCommonFrame,代码行数:27,代码来源:BitmapUtil.java

示例12: createFillDrawable

import android.graphics.drawable.StateListDrawable; //导入依赖的package包/类
@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;
}
 
开发者ID:WeiMei-Tian,项目名称:editor-sql,代码行数:25,代码来源:FloatingActionButton.java

示例13: initIdleStateDrawable

import android.graphics.drawable.StateListDrawable; //导入依赖的package包/类
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());
}
 
开发者ID:fergus825,项目名称:SmartOrnament,代码行数:20,代码来源:CircularProgressButton.java

示例14: onActionUp

import android.graphics.drawable.StateListDrawable; //导入依赖的package包/类
@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);
    }
 
开发者ID:Blankeer,项目名称:MDWechat,代码行数:18,代码来源:Label.java

示例15: testCreateMultiStateDrawable

import android.graphics.drawable.StateListDrawable; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:milosmns,项目名称:silly-android,代码行数:26,代码来源:ColoringTest.java


注:本文中的android.graphics.drawable.StateListDrawable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。