本文整理汇总了Java中android.graphics.drawable.ShapeDrawable.setShape方法的典型用法代码示例。如果您正苦于以下问题:Java ShapeDrawable.setShape方法的具体用法?Java ShapeDrawable.setShape怎么用?Java ShapeDrawable.setShape使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.drawable.ShapeDrawable
的用法示例。
在下文中一共展示了ShapeDrawable.setShape方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCornerDrawable
import android.graphics.drawable.ShapeDrawable; //导入方法依赖的package包/类
public static Drawable getCornerDrawable(float topLeft,
float topRight,
float bottomLeft,
float bottomRight,
@ColorInt int color) {
float[] outerR = new float[8];
outerR[0] = topLeft;
outerR[1] = topLeft;
outerR[2] = topRight;
outerR[3] = topRight;
outerR[4] = bottomRight;
outerR[5] = bottomRight;
outerR[6] = bottomLeft;
outerR[7] = bottomLeft;
ShapeDrawable drawable = new ShapeDrawable();
drawable.setShape(new RoundRectShape(outerR, null, null));
drawable.getPaint().setColor(color);
return drawable;
}
示例2: createProductImageDrawable
import android.graphics.drawable.ShapeDrawable; //导入方法依赖的package包/类
private Drawable createProductImageDrawable(Product product) {
final ShapeDrawable background = new ShapeDrawable();
background.setShape(new OvalShape());
background.getPaint().setColor(ContextCompat.getColor(getContext(), product.color));
final BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(),
BitmapFactory.decodeResource(getResources(), product.image));
final LayerDrawable layerDrawable = new LayerDrawable
(new Drawable[]{background, bitmapDrawable});
final int padding = (int) getResources().getDimension(R.dimen.spacing_huge);
layerDrawable.setLayerInset(1, padding, padding, padding, padding);
return layerDrawable;
}
示例3: getBackground
import android.graphics.drawable.ShapeDrawable; //导入方法依赖的package包/类
private static Drawable getBackground(int normalStateColor,
int pressedStateColor) {
StateListDrawable background = new StateListDrawable();
int c = SizeUtil.dp10;
float[] r = new float[] {c, c, c, c, c, c, c, c};
RoundRectShape rr = new RoundRectShape(r, null, null);
ShapeDrawable cd = new ShapeDrawable();
cd.setShape(rr);
cd.getPaint().setColor(pressedStateColor);
background.addState(new int[] {android.R.attr.state_pressed,
android.R.attr.state_focused}, cd);
background.addState(new int[] {-android.R.attr.state_pressed,
android.R.attr.state_focused}, cd);
background.addState(new int[] {android.R.attr.state_pressed,
-android.R.attr.state_focused}, cd);
ShapeDrawable cd1 = new ShapeDrawable();
cd1.setShape(rr);
cd1.getPaint().setColor(normalStateColor);
background.addState(new int[] {-android.R.attr.state_pressed,
-android.R.attr.state_focused}, cd1);
return background;
}
示例4: createBackgroundImageView
import android.graphics.drawable.ShapeDrawable; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private ImageView createBackgroundImageView(Context context, boolean fullscreen) {
BackgroundImageView view = new BackgroundImageView(context, fullscreen);
view.setScaleType(ImageView.ScaleType.CENTER_CROP);
int cornerRadius;
if (!fullscreen) {
cornerRadius = SizeUtil.dp20;
} else {
cornerRadius = 0;
}
view.setImageBitmap(options.getBackgroundImage());
ShapeDrawable footerBackground = new ShapeDrawable();
footerBackground.setShape(createRoundRect(cornerRadius));
footerBackground.getPaint().setColor(options.getBackgroundColor());
if (Build.VERSION.SDK_INT >= 16) {
view.setBackground(footerBackground);
} else {
view.setBackgroundDrawable(footerBackground);
}
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
view.setLayoutParams(layoutParams);
return view;
}
示例5: createProductImageDrawable
import android.graphics.drawable.ShapeDrawable; //导入方法依赖的package包/类
private Drawable createProductImageDrawable(Product product) {
final ShapeDrawable background = new ShapeDrawable();
background.setShape(new OvalShape());
background.getPaint().setColor(ContextCompat.getColor(getContext(), product.color));
final BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(),
BitmapFactory.decodeResource(getResources(), product.image));
final LayerDrawable layerDrawable = new LayerDrawable
(new Drawable[]{background, bitmapDrawable});
final int padding = (int) getResources().getDimension(R.dimen.spacing_huge);
layerDrawable.setLayerInset(1, padding, padding, padding, padding);
return layerDrawable;
}
示例6: setShape
import android.graphics.drawable.ShapeDrawable; //导入方法依赖的package包/类
private void setShape() {
ShapeDrawable drawable = new ShapeDrawable();
// Set color of drawable.
drawable.getPaint().setColor((backgroundColor == Component.COLOR_DEFAULT)
? SHAPED_DEFAULT_BACKGROUND_COLOR : backgroundColor);
// Set shape of drawable.
switch (shape) {
case Component.BUTTON_SHAPE_ROUNDED:
drawable.setShape(new RoundRectShape(ROUNDED_CORNERS_ARRAY, null, null));
break;
case Component.BUTTON_SHAPE_RECT:
drawable.setShape(new RectShape());
break;
case Component.BUTTON_SHAPE_OVAL:
drawable.setShape(new OvalShape());
break;
default:
throw new IllegalArgumentException();
}
// Set drawable to the background of the button.
view.setBackgroundDrawable(drawable);
view.invalidate();
}