當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。