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


Java GradientDrawable类代码示例

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


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

示例1: setPreviewColor

import android.graphics.drawable.GradientDrawable; //导入依赖的package包/类
private void setPreviewColor(@NonNull String value) {
  int color;

  switch (value) {
    case "green":   color = getContext().getResources().getColor(R.color.green_500);   break;
    case "red":     color = getContext().getResources().getColor(R.color.red_500);     break;
    case "blue":    color = getContext().getResources().getColor(R.color.blue_500);    break;
    case "yellow":  color = getContext().getResources().getColor(R.color.yellow_500);  break;
    case "cyan":    color = getContext().getResources().getColor(R.color.cyan_500);    break;
    case "magenta": color = getContext().getResources().getColor(R.color.pink_500);    break;
    case "white":   color = getContext().getResources().getColor(R.color.white);       break;
    default:        color = getContext().getResources().getColor(R.color.transparent); break;
  }

  if (colorImageView != null) {
    GradientDrawable drawable = new GradientDrawable();
    drawable.setShape(GradientDrawable.OVAL);
    drawable.setColor(color);

    colorImageView.setImageDrawable(drawable);
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:23,代码来源:LEDColorListPreference.java

示例2: createCornerBgPressed

import android.graphics.drawable.GradientDrawable; //导入依赖的package包/类
/**被按下时的背景*/
public static Drawable createCornerBgPressed(Context c) {
	SizeHelper.prepare(c);

	// prepare
	int strokeWidth = SizeHelper.fromPxWidth(1);
	int roundRadius = SizeHelper.fromPxWidth(6);
	int strokeColor = Color.parseColor("#ffc9c9cb");
	int fillColor = Color.parseColor("#afc9c9cb");

	GradientDrawable gd = new GradientDrawable();
	gd.setColor(fillColor);
	gd.setCornerRadius(roundRadius);
	gd.setStroke(strokeWidth, strokeColor);

	return gd;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:DrawableHelper.java

示例3: initBorder

import android.graphics.drawable.GradientDrawable; //导入依赖的package包/类
private void initBorder() {
//        if (mWipeOffBorder || mIdentity == null || !mIdentity.officialMember) {
//            mDrawable = null;
//            setBackground(null);
//            return;
//        }

        if (mDrawable == null) {
            float radius = 4f;

            GradientDrawable gradientDrawable = new GradientDrawable();
            gradientDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
            gradientDrawable.setShape(GradientDrawable.RECTANGLE);
            gradientDrawable.setDither(true);
            gradientDrawable.setStroke(STROKE_SIZE, mColor);
            gradientDrawable.setCornerRadius(radius);

            mDrawable = gradientDrawable;
        } else {
            mDrawable.setStroke(STROKE_SIZE, mColor);
        }

        setBackground(mDrawable);
    }
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:25,代码来源:IdentityView.java

示例4: drawCurrentPageShadow

import android.graphics.drawable.GradientDrawable; //导入依赖的package包/类
@Override
protected void drawCurrentPageShadow(Canvas canvas) {
    canvas.save();
    GradientDrawable shadow;
    if (actiondownX > mScreenWidth >> 1) {
        shadow = mBackShadowDrawableLR;
        shadow.setBounds((int) (mScreenWidth + touch_down - 5), 0, (int) (mScreenWidth + touch_down + 5), mScreenHeight);

    } else {
        shadow = mBackShadowDrawableRL;
        shadow.setBounds((int) (touch_down - 5), 0, (int) (touch_down + 5), mScreenHeight);
    }
    shadow.draw(canvas);
    try {
        canvas.restore();
    } catch (Exception e) {

    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:OverlappedWidget.java

示例5: createRippleDrawable

import android.graphics.drawable.GradientDrawable; //导入依赖的package包/类
/**
 * Creates a new {@link RippleDrawable} introduced in Lollipop.
 *
 * @param normalColor  Color for the idle/normal state
 * @param rippleColor  Color for the ripple effect
 * @param bounds       Clipping bounds for the ripple state. Set to {@code null} to get a borderless ripple
 * @param cornerRadius Set to round the corners on rectangular drawables, 0 to disable
 * @return A fully colored RippleDrawable, new instance each time
 */
@NonNull
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public static RippleDrawable createRippleDrawable(@ColorInt final int normalColor, @ColorInt final int rippleColor, @Nullable final Rect bounds,
                                                  @IntRange(from = 0) final int cornerRadius) {
    Drawable maskDrawable = null;
    if (bounds != null) {
        // clip color is white
        maskDrawable = createColoredDrawable(Color.WHITE, bounds);
        if (maskDrawable instanceof GradientDrawable) {
            ((GradientDrawable) maskDrawable).setCornerRadius(cornerRadius);
        }
        maskDrawable.setBounds(bounds);
    }

    Drawable normalStateDrawable = null;
    // transparent has no idle state
    if (normalColor != Color.TRANSPARENT) {
        normalStateDrawable = createColoredDrawable(normalColor, bounds);
        if (normalStateDrawable instanceof GradientDrawable) {
            ((GradientDrawable) normalStateDrawable).setCornerRadius(cornerRadius);
        }
    }

    return new RippleDrawable(ColorStateList.valueOf(rippleColor), normalStateDrawable, maskDrawable);
}
 
开发者ID:milosmns,项目名称:silly-android,代码行数:35,代码来源:Coloring.java

示例6: ViewfinderView

import android.graphics.drawable.GradientDrawable; //导入依赖的package包/类
public ViewfinderView(Context context, AttributeSet attrs) {
    super(context, attrs);
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint2 = new Paint(Paint.ANTI_ALIAS_FLAG);
    Resources resources = getResources();
    maskColor = Color.parseColor("#60000000");//resources.getColor(R.color.viewfinder_mask);
    resultColor = Color.parseColor("#b0000000");//resources.getColor(R.color.result_view);

    // GradientDrawable、lineDrawable
    mRect = new Rect();
    int left = Color.RED;//getResources().getColor(R.color.lightgreen);
    //getResources().getColor(R.color.green);
    //mCenterColor = Color.RED;
    setCenterColor(Color.RED);
    int right = Color.RED;//getResources().getColor(R.color.lightgreen);
    //lineDrawable = resources.getDrawable(R.drawable.zx_code_line);
    mDrawable = new GradientDrawable(
            GradientDrawable.Orientation.LEFT_RIGHT, new int[]{left,
            left, mCenterColor, right, right});

    scannerAlpha = 0;
    possibleResultPoints = new ArrayList<>(5);
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:24,代码来源:ViewfinderView.java

示例7: FlatToast

import android.graphics.drawable.GradientDrawable; //导入依赖的package包/类
public FlatToast(Context context) {
    super(context);
    mContext = context;
    
    //toast text
    textView = new TextView(context);
    textView.setTextColor(Color.WHITE);
    textView.setTextSize(17);
    textView.setPadding(Utils.dip2px(context, 15), Utils.dip2px(context, 8), Utils.dip2px(context, 15), Utils.dip2px(context, 8));
    
    //toast background
    gradientDrawable = new GradientDrawable();
    gradientDrawable.setColor(Color.parseColor("#212121"));
    gradientDrawable.setAlpha(200);
    gradientDrawable.setCornerRadius(Utils.dip2px(context, 10));
}
 
开发者ID:AstinPE,项目名称:StarchWindow,代码行数:17,代码来源:FlatToast.java

示例8: updateDrawable

import android.graphics.drawable.GradientDrawable; //导入依赖的package包/类
private void updateDrawable(int strokeColor) {

            int mbackgroundColor;
            if (isChecked) {
                mbackgroundColor = selectedBackgroundColor;
            } else {
                mbackgroundColor = backgroundColor;
            }

            GradientDrawable drawable = new GradientDrawable();
            drawable.setCornerRadii(mRadius);
            drawable.setColor(mbackgroundColor);
            drawable.setStroke(mStrokeWidth, strokeColor);

            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                this.setBackgroundDrawable(drawable);
            } else {
                this.setBackground(drawable);
            }
        }
 
开发者ID:Lazyeraser,项目名称:DereHelper,代码行数:21,代码来源:MultiLineChooseLayout.java

示例9: getDropShadowOrientation

import android.graphics.drawable.GradientDrawable; //导入依赖的package包/类
protected GradientDrawable.Orientation getDropShadowOrientation() {
    // Gets the orientation for the static and sliding drawer. The overlay drawer provides its own implementation.
    switch (getPosition()) {
        case TOP:
            return GradientDrawable.Orientation.BOTTOM_TOP;

        case RIGHT:
            return GradientDrawable.Orientation.LEFT_RIGHT;

        case BOTTOM:
            return GradientDrawable.Orientation.TOP_BOTTOM;

        default:
            return GradientDrawable.Orientation.RIGHT_LEFT;
    }
}
 
开发者ID:ultrasonic,项目名称:ultrasonic,代码行数:17,代码来源:MenuDrawer.java

示例10: getGradientDrawable

import android.graphics.drawable.GradientDrawable; //导入依赖的package包/类
private Drawable getGradientDrawable(float mCornerRadius,
                                     int mStrokeColor, int mSolidColor, int mStrokeWidth,
                                     float mDashWidth, float mDashGap,
                                     float mTopLeftRadius, float mTopRightRadius,
                                     float mBottomLeftRadius, float mBottomRightRadius) {
    GradientDrawable gradientDrawable = new GradientDrawable();
    gradientDrawable.setColor(mSolidColor);
    gradientDrawable.setStroke(mStrokeWidth, mStrokeColor, mDashWidth, mDashGap);
    float[] radius = {mTopLeftRadius, mTopLeftRadius, mTopRightRadius, mTopRightRadius, mBottomRightRadius,
            mBottomRightRadius, mBottomLeftRadius, mBottomLeftRadius};

    if (mCornerRadius == DEFAULT_CORNER_RADIUS) {
        gradientDrawable.setCornerRadii(radius);
    } else {
        gradientDrawable.setCornerRadius(mCornerRadius);
    }
    return gradientDrawable;
}
 
开发者ID:z-chu,项目名称:FriendBook,代码行数:19,代码来源:SuperConfig.java

示例11: setDrawableColor

import android.graphics.drawable.GradientDrawable; //导入依赖的package包/类
/**
 * Sets the background color of the drawable
 **/
public static void setDrawableColor(Context context, Drawable drawable, @AttrRes int colorAttrRes) {
    int colorRes = getResourceId(context, colorAttrRes);
    int color = ContextCompat.getColor(context, colorRes);
    if (drawable instanceof ShapeDrawable) {
        ((ShapeDrawable) drawable).getPaint().setColor(color);
    } else if (drawable instanceof GradientDrawable) {
        ((GradientDrawable) drawable).setColor(color);
    } else if (drawable instanceof ColorDrawable) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            ((ColorDrawable) drawable).setColor(color);
        }
    } else if (drawable instanceof RotateDrawable) {
        setDrawableColor(context, ((RotateDrawable) drawable).getDrawable(), colorAttrRes);
    }
}
 
开发者ID:kaliturin,项目名称:BlackList,代码行数:19,代码来源:Utils.java

示例12: morphParent

import android.graphics.drawable.GradientDrawable; //导入依赖的package包/类
private AnimatorSet morphParent(int duration){
    GradientDrawable drawable=GradientDrawable.class.cast(parent.getBackground());
    int endValue=isFolded?getResources().getDimensionPixelOffset(R.dimen.morph_radius):0;
    ObjectAnimator cornerAnimation = ObjectAnimator.ofFloat(drawable, "cornerRadius", endValue);
    endValue=isFolded?parent.getHeight()/2:parent.getHeight()*2;
    ValueAnimator heightAnimation = ValueAnimator.ofInt(parent.getHeight(),endValue);
    heightAnimation.addUpdateListener(valueAnimator-> {
        int val = (Integer) valueAnimator.getAnimatedValue();
        ViewGroup.LayoutParams layoutParams = parent.getLayoutParams();
        layoutParams.height = val;
        parent.setLayoutParams(layoutParams);
    });
    cornerAnimation.setDuration(duration);
    heightAnimation.setDuration(duration);
    AnimatorSet set=new AnimatorSet();
    set.playTogether(cornerAnimation,heightAnimation);
    return set;
}
 
开发者ID:vpaliyX,项目名称:Material-Motion,代码行数:19,代码来源:DotsFragment.java

示例13: drawPathAHorizontalShadow

import android.graphics.drawable.GradientDrawable; //导入依赖的package包/类
/**
 * 绘制A区域水平翻页阴影
 * @param canvas
 */
private void drawPathAHorizontalShadow(Canvas canvas, Path pathA){
    canvas.restore();
    canvas.save();
    canvas.clipPath(pathA, Region.Op.INTERSECT);

    int maxShadowWidth = 30;//阴影矩形最大的宽度
    int left = (int) (a.x - Math.min(maxShadowWidth,(rPathAShadowDis/2)));
    int right = (int) (a.x);
    int top = 0;
    int bottom = viewHeight;
    GradientDrawable gradientDrawable = drawableHorizontalLowerRight;
    gradientDrawable.setBounds(left,top,right,bottom);

    float mDegrees = (float) Math.toDegrees(Math.atan2(f.x-a.x,f.y-h.y));
    canvas.rotate(mDegrees, a.x, a.y);
    gradientDrawable.draw(canvas);
}
 
开发者ID:AnliaLee,项目名称:BookPage,代码行数:22,代码来源:BookPageView.java

示例14: init

import android.graphics.drawable.GradientDrawable; //导入依赖的package包/类
private void init(Context context){
    defaultWidth = 600;
    defaultHeight = 1000;
    pageNum = 1;
    scrollPageLeft = 0;
    scrollTime = 300;
    touchStyle = TOUCH_RIGHT;
    pageState = PAGE_STAY;

    touchPoint = new MyPoint(-1,-1);
    mScroller = new Scroller(context,new LinearInterpolator());

    int[] mBackShadowColors = new int[] { 0x66000000,0x00000000};
    shadowDrawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, mBackShadowColors);
    shadowDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
}
 
开发者ID:AnliaLee,项目名称:BookPage,代码行数:17,代码来源:CoverPageView.java

示例15: changeBackground

import android.graphics.drawable.GradientDrawable; //导入依赖的package包/类
public void changeBackground() {
	if (iSchecked) {
		if (!isInEditMode()) {
			setBackgroundResource(R.drawable.background_checkbox);
			LayerDrawable layer = (LayerDrawable) getBackground();
			GradientDrawable shape = (GradientDrawable) layer
					.findDrawableByLayerId(R.id.shape_bacground);
			shape.setColor(backgroundColor);
		}

	} else {
		if (!isInEditMode()) {
			setBackgroundResource(R.drawable.background_switch_ball_uncheck);
		}
	}
}
 
开发者ID:mityung,项目名称:XERUNG,代码行数:17,代码来源:Switch.java


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