本文整理汇总了Java中android.graphics.drawable.GradientDrawable.setColor方法的典型用法代码示例。如果您正苦于以下问题:Java GradientDrawable.setColor方法的具体用法?Java GradientDrawable.setColor怎么用?Java GradientDrawable.setColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.drawable.GradientDrawable
的用法示例。
在下文中一共展示了GradientDrawable.setColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setBackgroundColor
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
@Override
public void setBackgroundColor(int color) {
backgroundColor = color;
if (isEnabled()) {
beforeBackground = backgroundColor;
}
try {
LayerDrawable layer = (LayerDrawable) getBackground();
// 每个按钮的框架都是由drawable中的xml文件制定的,xml文件中都有一个item的id叫:shape_bacground
GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
/**
* 给这个图片设置背景色,因为图片的主体是透明的所以可以直接显示背景色
* 效果就是一个透明但有阴影的框架下有了背景色,这样的方式可以方便的设置不同颜色的按钮,让按钮看起来还是浑然一体
*/
shape.setColor(backgroundColor);
/**
* 当重新设定背景色后,要检查涟漪颜色。如果已经设定了涟漪颜色,那么就用之前的。如果没设定就重新生成
*/
if (!settedRippleColor) {
rippleColor = makePressColor(255);
}
} catch (Exception ex) {
// Without bacground
}
}
示例2: build
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
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;
}
示例3: 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));
}
示例4: updateSelectedColorPreview
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
private void updateSelectedColorPreview() {
// Create color with selected color values
int redValue = seekBarRed.getProgress();
int greenValue = seekBarGreen.getProgress();
int blueValue = seekBarBlue.getProgress();
int alpha = seekBarAlpha.getProgress();
selectedColor = Color.argb(alpha, redValue, greenValue, blueValue);
GradientDrawable previewBackground = (GradientDrawable) selectedColorPreview.getBackground();
previewBackground.setColor(selectedColor);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
selectedColorPreview.setBackground(previewBackground);
}
else {
selectedColorPreview.setBackgroundDrawable(previewBackground);
}
}
示例5: loadHintView
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
/**
* 加载hintView的容器
*/
private void loadHintView(){
addView(mHintView);
mHintView.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
((View) mHintView).setLayoutParams(lp);
GradientDrawable gd = new GradientDrawable();
gd.setColor(color);
gd.setAlpha(alpha);
mHintView.setBackgroundDrawable(gd);
mHintViewDelegate.initView(mAdapter == null ? 0 : mAdapter.getCount(),
gravity, (BaseHintView) mHintView);
}
示例6: createDrawable
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
private GradientDrawable createDrawable(int color, int cornerColor, int cornerSize, int cornerRadius) {
GradientDrawable out = new GradientDrawable();
out.setColor(color);
out.setStroke(cornerSize, cornerColor);
out.setCornerRadius(cornerRadius);
return out;
}
示例7: onBindViewHolder
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
/**
* Called by the RecyclerView to display data at a specified position in the Cursor.
*
* @param holder The ViewHolder to bind Cursor data to
* @param position The position of the data in the Cursor
*/
@Override
public void onBindViewHolder(TaskViewHolder holder, int position) {
// Indices for the _id, description, and priority columns
int idIndex = mCursor.getColumnIndex(TaskContract.TaskEntry._ID);
int descriptionIndex = mCursor.getColumnIndex(TaskContract.TaskEntry.COLUMN_DESCRIPTION);
int priorityIndex = mCursor.getColumnIndex(TaskContract.TaskEntry.COLUMN_PRIORITY);
mCursor.moveToPosition(position); // get to the right location in the cursor
// Determine the values of the wanted data
final int id = mCursor.getInt(idIndex);
String description = mCursor.getString(descriptionIndex);
int priority = mCursor.getInt(priorityIndex);
//Set values
holder.itemView.setTag(id);
holder.taskDescriptionView.setText(description);
// Programmatically set the text and color for the priority TextView
String priorityString = "" + priority; // converts int to String
holder.priorityView.setText(priorityString);
GradientDrawable priorityCircle = (GradientDrawable) holder.priorityView.getBackground();
// Get the appropriate background color based on the priority
int priorityColor = getPriorityColor(priority);
priorityCircle.setColor(priorityColor);
}
示例8: makeNormalDrawable
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
@Override
public Drawable makeNormalDrawable() {
GradientDrawable dot_normal = new GradientDrawable();
dot_normal.setColor(normalColor);
dot_normal.setCornerRadius(SizeUtil.dip2px(getContext(), 4));
dot_normal.setSize(SizeUtil.dip2px(getContext(), 8), SizeUtil.dip2px(getContext(), 8));
return dot_normal;
}
示例9: changeBackground
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
public void changeBackground() {
if (!isInEditMode()) {
if (value != min) {
setBackgroundResource(R.drawable.background_checkbox);
LayerDrawable layer = (LayerDrawable) getBackground();
GradientDrawable shape = (GradientDrawable) layer
.findDrawableByLayerId(R.id.shape_bacground);
shape.setColor(backgroundColor);
} else {
setBackgroundResource(R.drawable.background_switch_ball_uncheck);
}
}
}
示例10: makeFocusDrawable
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
@Override
public Drawable makeFocusDrawable() {
GradientDrawable dot_focus = new GradientDrawable();
dot_focus.setColor(focusColor);
dot_focus.setCornerRadius(SizeUtil.dip2px(getContext(), 4));
dot_focus.setSize(SizeUtil.dip2px(getContext(), 8), SizeUtil.dip2px(getContext(), 8));
return dot_focus;
}
示例11: setupBadgeBackgroundColors
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
private void setupBadgeBackgroundColors(String BADGE_COLOR) {
GradientDrawable gd = (GradientDrawable) outer_container.getBackground();
gd.setColor(Color.parseColor(BADGE_COLOR));
LayerDrawable layers = (LayerDrawable) bottom_arrow.getBackground();
RotateDrawable rotate = (RotateDrawable) layers.findDrawableByLayerId(R.id.grad);
GradientDrawable drawable = (GradientDrawable) rotate.getDrawable();
drawable.setColor(Color.parseColor(BADGE_COLOR));
}
示例12: getGradientDrawable
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
public GradientDrawable getGradientDrawable(int strokeWidth,int strokeColor,int fillColor){
GradientDrawable gd = new GradientDrawable();//创建drawable
gd.setColor(fillColor);
gd.setShape(GradientDrawable.OVAL);
gd.setSize(100, 100);
gd.setStroke(strokeWidth, strokeColor);
return gd;
}
示例13: makeFocusDrawable
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
@Override
public Drawable makeFocusDrawable()
{
GradientDrawable dot_focus = new GradientDrawable();
dot_focus.setColor(focusColor);
dot_focus.setCornerRadius(dump.v.Util.dip2px(getContext(), 4));
dot_focus.setSize(dump.v.Util.dip2px(getContext(), 8), dump.v.Util.dip2px(getContext(), 8));
return dot_focus;
}
示例14: getBadgeDrawable
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
static GradientDrawable getBadgeDrawable(BadgeItem badgeItem, Context context) {
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
shape.setCornerRadius(context.getResources().getDimensionPixelSize(R.dimen.badge_corner_radius));
shape.setColor(badgeItem.getBackgroundColor(context));
shape.setStroke(badgeItem.getBorderWidth(), badgeItem.getBorderColor(context));
return shape;
}
示例15: createGradientDrawable
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
public static GradientDrawable createGradientDrawable(int radious, int color) {
GradientDrawable drawable = new GradientDrawable();
drawable.setColor(color);
drawable.setCornerRadius((float) radious);
return drawable;
}