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


Java StateListDrawable.addState方法代码示例

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


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

示例1: 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

示例2: onInflateTabView

import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
@NonNull
@Override
protected final View onInflateTabView(@NonNull final LayoutInflater inflater,
                                      @Nullable final ViewGroup parent,
                                      @NonNull final AbstractTabViewHolder viewHolder) {
    View view = inflater.inflate(R.layout.tablet_tab, parent, false);
    StateListDrawable backgroundDrawable = new StateListDrawable();
    Drawable defaultDrawable = ContextCompat
            .getDrawable(getModel().getContext(), R.drawable.tablet_tab_background);
    Drawable selectedDrawable = ContextCompat
            .getDrawable(getModel().getContext(), R.drawable.tablet_tab_background_selected);
    backgroundDrawable.addState(new int[]{android.R.attr.state_selected}, selectedDrawable);
    backgroundDrawable.addState(StateSet.WILD_CARD, defaultDrawable);
    ViewUtil.setBackground(view, backgroundDrawable);
    return view;
}
 
开发者ID:michael-rapp,项目名称:ChromeLikeTabSwitcher,代码行数:17,代码来源:TabletTabRecyclerAdapter.java

示例3: generateRoundDrawable

import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
public static Drawable generateRoundDrawable(float radiiL, float radiiR, int pressColor, int defaultColor) {
    //外环的圆角矩形
    float[] outRadii = new float[]{radiiL, radiiL, radiiR, radiiR, radiiR, radiiR, radiiL, radiiL};//四个角的 圆角幅度,8个可以设置的值,每个角都有2个边 2*4=8个

    //与内环的距离
    RectF inset = new RectF(0, 0, 0, 0);

    //按下状态
    Shape roundRectShape = new RoundRectShape(outRadii, inset, null);//圆角背景
    ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圆角shape
    shopDrawablePress.getPaint().setColor(pressColor);//设置颜色

    //正常状态
    Shape roundRectShapeNormal = new RoundRectShape(outRadii, inset, 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,代码行数:24,代码来源:ResUtil.java

示例4: addItem

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

示例5: setBgSelector

import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
public void setBgSelector() {
    StateListDrawable bg = new StateListDrawable();

    setDrawable(gd_background, backgroundColor, strokeColor);
    bg.addState(new int[]{-android.R.attr.state_pressed}, gd_background);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {//16
        setBackground(bg);
    } else {
        //noinspection deprecation
        setBackgroundDrawable(bg);
    }
}
 
开发者ID:ynztlxdeai,项目名称:MVPtemplate,代码行数:14,代码来源:MsgView.java

示例6: makeSelector

import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
private StateListDrawable makeSelector(int color) {
    StateListDrawable res = new StateListDrawable();
    res.setExitFadeDuration(150);
    GradientDrawable pressed_drawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,new int[] {getLightenColor(color),getLightenColor(color)});
    pressed_drawable.setCornerRadius(resources.getDimensionPixelSize(R.dimen.pdlg_corner_radius));
    GradientDrawable default_drawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,new int[] {color,color});
    default_drawable.setCornerRadius(resources.getDimensionPixelSize(R.dimen.pdlg_corner_radius));
    res.addState(new int[]{android.R.attr.state_pressed}, pressed_drawable);
    res.addState(new int[]{}, default_drawable);
    return res;
}
 
开发者ID:mjn1369,项目名称:PrettyDialog,代码行数:12,代码来源:PrettyDialogButton.java

示例7: createFillDrawable

import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
private StateListDrawable createFillDrawable(float strokeWidth) {
  StateListDrawable drawable = new StateListDrawable();
  drawable.addState(new int[] { -android.R.attr.state_enabled }, createCircleDrawable(mColorDisabled, strokeWidth));
  drawable.addState(new int[] { android.R.attr.state_pressed }, createCircleDrawable(mColorPressed, strokeWidth));
  drawable.addState(new int[] { }, createCircleDrawable(mColorNormal, strokeWidth));
  return drawable;
}
 
开发者ID:nhocga1995s,项目名称:MyCalendar,代码行数:8,代码来源:FloatingActionButtonLibrary.java

示例8: create

import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
public StateListDrawable create() {
    StateListDrawable selector = new StateListDrawable();
    if (hasSetDisabledDrawable)
        selector.addState(new int[]{-android.R.attr.state_enabled}, mDisabledDrawable);
    if (hasSetPressedDrawable)
        selector.addState(new int[]{android.R.attr.state_pressed}, mPressedDrawable);
    if (hasSetSelectedDrawable)
        selector.addState(new int[]{android.R.attr.state_selected}, mSelectedDrawable);
    if (hasSetFocusedDrawable)
        selector.addState(new int[]{android.R.attr.state_focused}, mFocusedDrawable);
    selector.addState(new int[]{}, mDefaultDrawable);
    return selector;
}
 
开发者ID:Wilshion,项目名称:HeadlineNews,代码行数:14,代码来源:SelectorFactory.java

示例9: getRadioButtonSelector

import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
/**
 * 通过代码配置一个selector XML对象 . . <br>
 * @author liulongzhenhai 2012-8-1 下午5:27:28 <br>
 * @param normal 没有状态
 * @param selected 选择状态
 * @param pressed 按下状态
 * @return 返回selector 的对象布局
 */
public static StateListDrawable getRadioButtonSelector(final Drawable normal, final Drawable selected,
                                                          final Drawable pressed) {
	final StateListDrawable drawable = new StateListDrawable();
	drawable.addState(new int[] { android.R.attr.state_focused, android.R.attr.state_enabled }, pressed);
	drawable.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }, normal);
	drawable.addState(new int[] { android.R.attr.state_checked, android.R.attr.state_enabled }, pressed);
	drawable.addState(new int[] { android.R.attr.state_selected, android.R.attr.state_enabled }, pressed);
	drawable.addState(new int[] {}, normal);
	return drawable;
}
 
开发者ID:VK2012,项目名称:AppCommonFrame,代码行数:19,代码来源:BitmapUtil.java

示例10: getSelectableDrawableFor

import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
@NonNull
public static Drawable getSelectableDrawableFor(int color) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        StateListDrawable stateListDrawable = new StateListDrawable();
        stateListDrawable.addState(
                new int[]{android.R.attr.state_pressed},
                new ColorDrawable(lightenOrDarken(color, 0.40D))
        );
        stateListDrawable.addState(
                new int[]{android.R.attr.state_focused},
                new ColorDrawable(lightenOrDarken(color, 0.80D))
        );
        stateListDrawable.addState(
                new int[]{},
                new ColorDrawable(color)
        );
        return stateListDrawable;
    } else {
        ColorStateList pressedColor = ColorStateList.valueOf(lightenOrDarken(color, 0.4D));
        ColorDrawable defaultColor = new ColorDrawable(color);
        ShapeDrawable shapeDrawable = (ShapeDrawable) getShapeWithColor(color);
        Drawable rippleColor = getRippleColor(color);
        return new RippleDrawable(
                pressedColor,
                shapeDrawable,
                rippleColor
        );
    }
}
 
开发者ID:goutham106,项目名称:GmArchMvvm,代码行数:30,代码来源:GmRipple.java

示例11: createFillDrawable

import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
/**
 * @param circleRect the defined rectangle
 * @param alpha      between  0 - 1
 * @return StateListDrawable
 */
protected StateListDrawable createFillDrawable(RectF circleRect, float alpha) {
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState(new int[]{android.R.attr.state_pressed}, createAlphaDrawble(circleRect, mColorPressed, alpha));
    drawable.addState(new int[]{}, createAlphaDrawble(circleRect, mColorNormal, alpha));
    return drawable;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:FloatingActionButton.java

示例12: generateStrokeDrawable

import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
public static Drawable generateStrokeDrawable(float radii, float borderWidth, int pressColor, int defaultColor, int disableColor) {
    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, inset, outRadii);//圆角背景
    ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圆角shape
    shopDrawablePress.getPaint().setColor(pressColor);//设置颜色

    ShapeDrawable shopDrawableEnable = new ShapeDrawable(roundRectShape);
    shopDrawableEnable.getPaint().setColor(disableColor);

    //正常状态
    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_enabled}, shopDrawableEnable);//按下状态
    bgStateDrawable.addState(new int[]{android.R.attr.state_checked}, shopDrawablePress);//按下状态
    bgStateDrawable.addState(new int[]{android.R.attr.state_pressed}, shopDrawablePress);//按下状态
    bgStateDrawable.addState(new int[]{android.R.attr.state_focused}, shopDrawablePress);//焦点状态
    bgStateDrawable.addState(new int[]{}, shopDrawableNormal);//其他状态

    return bgStateDrawable;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:29,代码来源:ResUtil.java

示例13: generateBackground

import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
private static Drawable generateBackground(int color, int fadeTime) {
    StateListDrawable drawable = new StateListDrawable();
    drawable.setExitFadeDuration(fadeTime);
    drawable.addState(new int[]{16842912}, generateCircleDrawable(color));
    if (VERSION.SDK_INT >= 21) {
        drawable.addState(new int[]{16842919}, generateRippleDrawable(color));
    } else {
        drawable.addState(new int[]{16842919}, generateCircleDrawable(color));
    }
    drawable.addState(new int[0], generateCircleDrawable(0));
    return drawable;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:13,代码来源:DayView.java

示例14: selectorChecked

import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
public static Drawable selectorChecked(Drawable normalDrawable, Drawable pressDrawable) {
    StateListDrawable listDrawable = new StateListDrawable();//状态shape
    listDrawable.addState(new int[]{android.R.attr.state_pressed}, pressDrawable);//按下状态
    listDrawable.addState(new int[]{android.R.attr.state_checked}, pressDrawable);//按下状态
    listDrawable.addState(new int[]{}, normalDrawable);//其他状态
    return listDrawable;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:8,代码来源:ResUtil.java

示例15: generateBackground

import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
private static Drawable generateBackground(int color, int fadeTime, Rect bounds) {
    StateListDrawable drawable = new StateListDrawable();
    drawable.setExitFadeDuration(fadeTime);
    drawable.addState(new int[]{android.R.attr.state_checked}, generateCircleDrawable(color));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        drawable.addState(new int[]{android.R.attr.state_pressed}, generateRippleDrawable(color, bounds));
    } else {
        drawable.addState(new int[]{android.R.attr.state_pressed}, generateCircleDrawable(color));
    }

    drawable.addState(new int[]{}, generateCircleDrawable(Color.TRANSPARENT));

    return drawable;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:DayView.java


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