本文整理匯總了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;
}