本文整理匯總了Java中android.graphics.drawable.GradientDrawable.setShape方法的典型用法代碼示例。如果您正苦於以下問題:Java GradientDrawable.setShape方法的具體用法?Java GradientDrawable.setShape怎麽用?Java GradientDrawable.setShape使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.drawable.GradientDrawable
的用法示例。
在下文中一共展示了GradientDrawable.setShape方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addPulseRing
import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
private void addPulseRing(LatLng latLng) {
GradientDrawable d = new GradientDrawable();
d.setShape(GradientDrawable.OVAL);
d.setSize(500, 500);
d.setColor(ContextCompat.getColor(this, R.color.pulse_color));
Bitmap bitmap = Bitmap.createBitmap(d.getIntrinsicWidth()
, d.getIntrinsicHeight()
, Bitmap.Config.ARGB_8888);
// Convert the drawable to bitmap
Canvas canvas = new Canvas(bitmap);
d.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
d.draw(canvas);
// Radius of the circle
final int radius = 100;
// Add the circle to the map
circle = mMap.addGroundOverlay(new GroundOverlayOptions()
.position(latLng, 2 * radius).image(BitmapDescriptorFactory.fromBitmap(bitmap)));
}
示例2: 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);
}
示例3: getBadgeDrawable
import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
/**
* @param context to fetch color
* @return return the background drawable
*/
private GradientDrawable getBadgeDrawable(Context context) {
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
shape.setCornerRadius(context.getResources().getDimensionPixelSize(R.dimen.badge_corner_radius));
shape.setColor(getBackgroundColor(context));
shape.setStroke(getBorderWidth(), getBorderColor(context));
return shape;
}
示例4: initView
import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
private void initView(Context context, AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundLatout);
//顯示類型
int shapeTpe = a.getInt(R.styleable.RoundLatout_viewShapeTpe, shapeTypes[0]);
//圓角大小
float cornerRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewCornerRadius, 0);
float topLeftRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewTopLeftRadius, 0);
float topRightRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewTopRightRadius, 0);
float bottomLeftRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewBottomLeftRadius, 0);
float bottomRightRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewBottomRightRadius, 0);
//填充色
int solidColor = a.getColor(R.styleable.RoundLatout_viewSolidColor, 0x0);
//邊框
int strokeColor = a.getColor(R.styleable.RoundLatout_viewStrokeColor, 0x0);
int strokeWidth = a.getDimensionPixelSize(R.styleable.RoundLatout_viewStrokeWidth, 0);
int strokeDashWidth = a.getDimensionPixelSize(R.styleable.RoundLatout_viewStrokeDashWidth, 0);
int strokeDashGap = a.getDimensionPixelSize(R.styleable.RoundLatout_viewStrokeDashGap, 0);
a.recycle();
GradientDrawable gd = new GradientDrawable();
gd.setColor(solidColor);
//設置類型
gd.setShape(shapeTypes[shapeTpe]);
//類型為矩形才可設置圓角
if (shapeTypes[shapeTpe] == GradientDrawable.RECTANGLE) {
if (cornerRadius != 0) {
gd.setCornerRadius(cornerRadius);
} else {
gd.setCornerRadii(new float[]{topLeftRadius, topLeftRadius, topRightRadius, topRightRadius, bottomRightRadius, bottomRightRadius, bottomLeftRadius, bottomLeftRadius});
}
}
gd.setStroke(strokeWidth, strokeColor, strokeDashWidth, strokeDashGap);
setBackground(gd);
}
示例5: createDrawable
import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
/**
* 效果比createSolidDrawable好
*/
public static Drawable createDrawable(int solidColor, float radii) {
GradientDrawable drawable = new GradientDrawable();
drawable.setShape(GradientDrawable.RECTANGLE);//設置形狀
drawable.setCornerRadius(radii);
drawable.setColor(solidColor);//請不要用透明顏色試圖隱藏solid
return drawable;
}
示例6: createBackgroundColorDrawable
import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
private Drawable createBackgroundColorDrawable() {
GradientDrawable mask = new GradientDrawable();
mask.setShape(GradientDrawable.OVAL);
if (mOutlineWidth != 0) {
mask.setStroke(mOutlineWidth, isColorDark(mColor) ? Color.WHITE : Color.BLACK);
}
mask.setColor(mColor);
return mask;
}
示例7: createButtonBackgroundDrawableBase
import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
private static Drawable createButtonBackgroundDrawableBase(int color, int cornerRadius) {
GradientDrawable d = new GradientDrawable();
d.setShape(GradientDrawable.RECTANGLE);
d.setCornerRadius(cornerRadius);
d.setColor(color);
return d;
}
示例8: createStateListDrawable
import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
/**
* @param radius 圓角角度
* @param color 填充顏色
* @return StateListDrawable 對象
* @author zy
*/
public static StateListDrawable createStateListDrawable(int radius, int color) {
StateListDrawable bg = new StateListDrawable();
GradientDrawable gradientStateNormal = new GradientDrawable();
gradientStateNormal.setColor(color);
gradientStateNormal.setShape(GradientDrawable.RECTANGLE);
gradientStateNormal.setCornerRadius(50);
gradientStateNormal.setStroke(0, 0);
bg.addState(View.EMPTY_STATE_SET, gradientStateNormal);
return bg;
}
示例9: 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;
}
示例10: createTileShape
import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
private static Drawable createTileShape(int backgroundColor, int borderColor) {
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
shape.setCornerRadii(new float[]{7, 7, 7, 7, 0, 0, 0, 0});
shape.setColor(backgroundColor);
shape.setStroke(1, borderColor);
shape.setBounds(7, 7, 7, 7);
return (shape);
}
示例11: CT
import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
public CT(Builder builder) {
LayoutInflater inflater = (LayoutInflater) builder.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_layout, null);
TextView tv = layout.findViewById(R.id.cltv);
tv.setText(builder.text);
tv.setTextColor(builder.textCol);
ImageView iv = layout.findViewById(R.id.cliv);
iv.setImageResource(builder.imageRes);
GradientDrawable shape = new GradientDrawable();
shape.setShape(builder.shape);
shape.setCornerRadii(new float[]{
builder.radiusTopLeft,
builder.radiusTopLeft,
builder.radiusTopRight,
builder.radiusTopRight,
builder.radiusBottomRight,
builder.radiusBottomRight,
builder.radiusBottomLeft,
builder.radiusBottomLeft
});
shape.setColor(builder.backCol);
shape.setStroke(builder.borderWidth, builder.borderCol);
layout.setBackgroundDrawable(shape);
Toast toast = new Toast(builder.context);
toast.setView(layout);
toast.setDuration(builder.toastDuration);
toast.setGravity(builder.toastGravity,0,100);
toast.show();
}
示例12: getItemShape
import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
private GradientDrawable getItemShape(int shape, int cornerRadius,
int solidColor, int strokeWidth, int strokeColor) {
GradientDrawable drawable = new GradientDrawable();
drawable.setShape(shape);
drawable.setStroke(strokeWidth, strokeColor);
drawable.setCornerRadius(cornerRadius);
drawable.setColor(solidColor);
return drawable;
}
示例13: addMenuView
import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
private void addMenuView(Context context, ImageView iv, TextView tv, boolean show) {
//SharedPreferences themePrefs = ApplicationLoader.applicationContext.getSharedPreferences(AndroidUtilities.THEME_PREFS, AndroidUtilities.THEME_PREFS_MODE);
//int cColor = themePrefs.getInt("chatsHeaderTabCounterColor", 0xffffffff);
//int bgColor = themePrefs.getInt("chatsHeaderTabCounterBGColor", 0xffff0000);
iv.setScaleType(ImageView.ScaleType.CENTER);
//int size = themePrefs.getInt("chatsHeaderTabCounterSize", 11);
//tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, size);
tv.setGravity(Gravity.RIGHT);
//tv.setTextColor(cColor);
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
shape.setCornerRadius(AndroidUtilities.dp(32));
//shape.setColor(bgColor);
tv.setBackgroundDrawable(shape);
//tv.setPadding(AndroidUtilities.dp(size > 10 ? size - 7 : 4), 0, AndroidUtilities.dp(size > 10 ? size - 7 : 4), 0);
RelativeLayout layout = new RelativeLayout(context);
layout.addView(iv, LayoutHelper.createRelative(50, LayoutHelper.MATCH_PARENT));
layout.addView(tv, LayoutHelper.createRelative(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, 0, 10, 5, 0, RelativeLayout.ALIGN_PARENT_RIGHT));
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) tv.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
tv.setLayoutParams(params);
if (show) {
menu.addView(layout, LayoutHelper.createLinear(50, LayoutHelper.MATCH_PARENT, 0));
}
// MenuCount(notifsCounter);
}
示例14: getIcFolderSelectedDrawable
import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
public static GradientDrawable getIcFolderSelectedDrawable( int color){
GradientDrawable gradientDrawable=new GradientDrawable();
gradientDrawable.setShape(GradientDrawable.OVAL);
gradientDrawable.setSize(SizeUtils.dp2px(24), SizeUtils.dp2px(24));
gradientDrawable.setBounds(0,0,SizeUtils.dp2px(24), SizeUtils.dp2px(24));
gradientDrawable.setColor(color);
return gradientDrawable;
}
示例15: refreshWeightProgress
import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
private void refreshWeightProgress() {
if (this.mUser != null && !isRemoved()) {
float latestWeight = getLatestWeight();
GradientDrawable drawable = new GradientDrawable();
drawable.setShape(1);
drawable.setColor(ViewCompat.MEASURED_SIZE_MASK);
float delta;
if (this.mUser.target_weight == -1.0f) {
this.tvProgress.setText("保持/塑形");
delta = latestWeight - this.mUser.begin_weight;
if (delta <= 0.0f) {
drawable.setStroke(5, getResources().getColor(R.color.hb));
this.tvDes.setText("比上次輕");
} else {
drawable.setStroke(5, getResources().getColor(R.color.jr));
this.tvDes.setText("比上次重");
}
this.tvWeight.setText(NumberUtils.safeToString(this.dFormat, (double) Math.abs
(delta)));
this.arcProgress.setVisibility(8);
} else {
float progress;
drawable.setStroke(1, 2113929215);
delta = latestWeight - this.mUser.begin_weight;
this.tvWeight.setText(NumberUtils.safeToString(this.dFormat, (double) Math.abs
(delta)));
if (delta <= 0.0f) {
this.tvDes.setText("已減重");
} else {
this.tvDes.setText("已增重");
}
if (this.mUser.begin_weight - latestWeight < 0.0f) {
progress = -1.0f;
} else if (this.mUser.begin_weight - this.mUser.target_weight <= 0.0f) {
progress = 0.0f;
} else {
progress = (this.mUser.begin_weight - latestWeight) / (this.mUser
.begin_weight - this.mUser.target_weight);
}
this.arcProgress.setVisibility(0);
this.arcProgress.setProgress(progress);
this.tvWeight.setText(NumberUtils.safeToString(this.dFormat, (double) Math.abs
(delta)));
this.tvProgress.setText(String.format("目標完成%d%%", new Object[]{Integer.valueOf
(Math.min(Math.max((int) (100.0f * progress), 0), 100))}));
}
this.rlProgress.setBackgroundDrawable(drawable);
}
}