本文整理匯總了Java中android.graphics.drawable.LayerDrawable類的典型用法代碼示例。如果您正苦於以下問題:Java LayerDrawable類的具體用法?Java LayerDrawable怎麽用?Java LayerDrawable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LayerDrawable類屬於android.graphics.drawable包,在下文中一共展示了LayerDrawable類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: create
import android.graphics.drawable.LayerDrawable; //導入依賴的package包/類
public Drawable create(Context context) {
final GradientDrawable bubble = new GradientDrawable();
final int radius = context.getResources().getDimensionPixelSize(R.dimen.message_bubble_corner_radius);
final float[] radii = cornerBooleansToRadii(corners, radius);
bubble.setColor(color);
bubble.setCornerRadii(radii);
if (!hasShadow) {
return bubble;
} else {
final GradientDrawable shadow = new GradientDrawable();
final int distance = context.getResources().getDimensionPixelSize(R.dimen.message_bubble_shadow_distance);
shadow.setColor(shadowColor);
shadow.setCornerRadii(radii);
final LayerDrawable layers = new LayerDrawable(new Drawable[]{shadow, bubble});
layers.setLayerInset(1, 0, 0, 0, distance);
return layers;
}
}
示例2: generateFinalDrawables
import android.graphics.drawable.LayerDrawable; //導入依賴的package包/類
protected LayerDrawable generateFinalDrawables(RectF circleRect) {
if (mSize == SIZE_NOSHADOW) {
return new LayerDrawable(
new Drawable[]{
createFillDrawable(circleRect),
createStrokesDrawable(circleRect),
getIconDrawable()
});
} else {
return new LayerDrawable(
new Drawable[]{
getResources().getDrawable(getDrawableBySize(mSize)),
createFillDrawable(circleRect),
createStrokesDrawable(circleRect),
getIconDrawable()
});
}
}
示例3: updateDrawableLayerTint
import android.graphics.drawable.LayerDrawable; //導入依賴的package包/類
/**
* Updates tint of a layer with the specified <var>layerId</var> of the wrapped drawable
* depends on the specified <var>stateSet</var>.
*
* @param layerId Id of the desired layer of which tint to update.
* @param stateSet State set to properly resolve tint color.
* @return {@code True} if tint has ben updated, {@code false} otherwise.
*/
private boolean updateDrawableLayerTint(int layerId, int[] stateSet) {
if ((mPrivateFlags & PFLAG_HAS_COLOR_FILTER) == 0) {
final Drawable drawable = ((LayerDrawable) mDrawable).findDrawableByLayerId(layerId);
if (drawable == null) {
return false;
}
final DrawableLayerTint layerTint = mDrawableLayerTints != null ? mDrawableLayerTints.get(layerId) : null;
if (layerTint != null && layerTint.tintList != null && layerTint.tintMode != null) {
final int tintColor = layerTint.tintList.getColorForState(stateSet, layerTint.currentTint);
if (tintColor != layerTint.currentTint || (mPrivateFlags & PFLAG_TINT_COLOR_CACHING_ENABLED) == 0) {
drawable.setColorFilter(new PorterDuffColorFilter(tintColor, layerTint.tintMode));
layerTint.currentTint = tintColor;
}
} else {
drawable.clearColorFilter();
}
return true;
}
return false;
}
示例4: initView
import android.graphics.drawable.LayerDrawable; //導入依賴的package包/類
@Override
public void initView() {
mRefreshLayout = findViewById(R.id.refreshLayout);
int deta = new Random().nextInt(7 * 24 * 60 * 60 * 1000);
mClassicsHeader = (ClassicsHeader)mRefreshLayout.getRefreshHeader();
mClassicsHeader.setLastUpdateTime(new Date(System.currentTimeMillis()-deta));
mClassicsHeader.setTimeFormat(new SimpleDateFormat("更新於 MM-dd HH:mm", Locale.CHINA));
mClassicsHeader.setTimeFormat(new DynamicTimeFormat("更新於 %s"));
mClassicsHeader.setSpinnerStyle(SpinnerStyle.Translate);
mDrawableProgress = mClassicsHeader.getProgressView().getDrawable();
if (mDrawableProgress instanceof LayerDrawable) {
mDrawableProgress = ((LayerDrawable) mDrawableProgress).getDrawable(0);
}
if (isFirstEnter) {
isFirstEnter = false;
//觸發自動刷新
mRefreshLayout.autoRefresh();
}
}
示例5: initBackground
import android.graphics.drawable.LayerDrawable; //導入依賴的package包/類
private void initBackground() {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
int progressColor = ThemeSwitcher.retrieveNavigationViewThemeColor(getContext(),
R.attr.navigationViewProgress);
int progressBackgroundColor = ThemeSwitcher.retrieveNavigationViewThemeColor(getContext(),
R.attr.navigationViewProgressBackground);
LayerDrawable progressBarDrawable = (LayerDrawable) alertProgressBar.getProgressDrawable();
// ProgressBar progress color
Drawable progressBackgroundDrawable = progressBarDrawable.getDrawable(0);
progressBackgroundDrawable.setColorFilter(progressBackgroundColor, PorterDuff.Mode.SRC_IN);
// ProgressBar background color
Drawable progressDrawable = progressBarDrawable.getDrawable(1);
progressDrawable.setColorFilter(progressColor, PorterDuff.Mode.SRC_IN);
// Hide the background
getBackground().setAlpha(0);
} else {
setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent));
}
}
示例6: getOrCreateReactViewBackground
import android.graphics.drawable.LayerDrawable; //導入依賴的package包/類
private ReactViewBackgroundDrawable getOrCreateReactViewBackground() {
if (mReactBackgroundDrawable == null) {
mReactBackgroundDrawable = new ReactViewBackgroundDrawable();
Drawable backgroundDrawable = getBackground();
super.setBackground(null); // required so that drawable callback is cleared before we add the
// drawable back as a part of LayerDrawable
if (backgroundDrawable == null) {
super.setBackground(mReactBackgroundDrawable);
} else {
LayerDrawable layerDrawable =
new LayerDrawable(new Drawable[]{mReactBackgroundDrawable, backgroundDrawable});
super.setBackground(layerDrawable);
}
}
return mReactBackgroundDrawable;
}
示例7: getOrCreateReactViewBackground
import android.graphics.drawable.LayerDrawable; //導入依賴的package包/類
private ReactViewBackgroundDrawable getOrCreateReactViewBackground() {
if (mReactBackgroundDrawable == null) {
mReactBackgroundDrawable = new ReactViewBackgroundDrawable();
Drawable backgroundDrawable = getBackground();
super.setBackground(null); // required so that drawable callback is cleared before we add the
// drawable back as a part of LayerDrawable
if (backgroundDrawable == null) {
super.setBackground(mReactBackgroundDrawable);
} else {
LayerDrawable layerDrawable =
new LayerDrawable(new Drawable[]{mReactBackgroundDrawable, backgroundDrawable});
super.setBackground(layerDrawable);
}
}
return mReactBackgroundDrawable;
}
示例8: createCircleDrawable
import android.graphics.drawable.LayerDrawable; //導入依賴的package包/類
private Drawable createCircleDrawable(int color, float strokeWidth) {
int alpha = Color.alpha(color);
int opaqueColor = opaque(color);
ShapeDrawable fillDrawable = new ShapeDrawable(new OvalShape());
final Paint paint = fillDrawable.getPaint();
paint.setAntiAlias(true);
paint.setColor(opaqueColor);
Drawable[] layers = {
fillDrawable,
createInnerStrokesDrawable(opaqueColor, strokeWidth)
};
LayerDrawable drawable = alpha == 255 || !mStrokeVisible
? new LayerDrawable(layers)
: new TranslucentLayerDrawable(alpha, layers);
int halfStrokeWidth = (int) (strokeWidth / 2f);
drawable.setLayerInset(1, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth);
return drawable;
}
示例9: styleSeekBar
import android.graphics.drawable.LayerDrawable; //導入依賴的package包/類
private void styleSeekBar() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
final Drawable progressDrawable = mSeekBar.getProgressDrawable();
if (progressDrawable != null) {
if (progressDrawable instanceof LayerDrawable) {
LayerDrawable ld = (LayerDrawable) progressDrawable;
int layers = ld.getNumberOfLayers();
for (int i = 0; i < layers; i++) {
ld.getDrawable(i).mutate().setColorFilter(mTintColor, PorterDuff.Mode.SRC_ATOP);
}
} else {
progressDrawable.mutate().setColorFilter(mTintColor, PorterDuff.Mode.SRC_ATOP);
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
final Drawable thumb = mSeekBar.getThumb();
if (thumb != null) {
thumb.mutate().setColorFilter(mTintColor, PorterDuff.Mode.SRC_ATOP);
}
}
}
}
示例10: changeBackground
import android.graphics.drawable.LayerDrawable; //導入依賴的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);
}
}
}
示例11: setBackgroundColor
import android.graphics.drawable.LayerDrawable; //導入依賴的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
}
}
示例12: createCircleDrawable
import android.graphics.drawable.LayerDrawable; //導入依賴的package包/類
private Drawable createCircleDrawable(int color, float strokeWidth) {
int alpha = Color.alpha(color);
int opaqueColor = opaque(color);
ShapeDrawable fillDrawable = new ShapeDrawable(new OvalShape());
final Paint paint = fillDrawable.getPaint();
paint.setAntiAlias(true);
paint.setColor(opaqueColor);
Drawable[] layers = {
fillDrawable,
createInnerStrokesDrawable(opaqueColor, strokeWidth)
};
LayerDrawable drawable = alpha == 255 || !mStrokeVisible
? new LayerDrawable(layers)
: new TranslucentLayerDrawable(alpha, layers);
int halfStrokeWidth = (int) (strokeWidth / 2f);
drawable.setLayerInset(1, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth);
return drawable;
}
示例13: createItemSeparatorBg
import android.graphics.drawable.LayerDrawable; //導入依賴的package包/類
/**
* 動態創建帶上分隔線或下分隔線的Drawable
*
* @param separatorColor
* @param bgColor
* @param top
* @return
*/
public static LayerDrawable createItemSeparatorBg(@ColorInt int separatorColor, @ColorInt int bgColor, int separatorHeight, boolean top) {
ShapeDrawable separator = new ShapeDrawable();
separator.getPaint().setStyle(Paint.Style.FILL);
separator.getPaint().setColor(separatorColor);
ShapeDrawable bg = new ShapeDrawable();
bg.getPaint().setStyle(Paint.Style.FILL);
bg.getPaint().setColor(bgColor);
Drawable[] layers = {separator, bg};
LayerDrawable layerDrawable = new LayerDrawable(layers);
layerDrawable.setLayerInset(1, 0, top ? separatorHeight : 0, 0, top ? 0 : separatorHeight);
return layerDrawable;
}
示例14: StrengthMeter
import android.graphics.drawable.LayerDrawable; //導入依賴的package包/類
public StrengthMeter(Context context, AttributeSet attrs) {
super(context, attrs, android.R.attr.progressBarStyleHorizontal);
bar = new ShapeDrawable();
bar.getPaint().setColor(RED);
ClipDrawable clip = new ClipDrawable(bar, LEFT, HORIZONTAL);
ShapeDrawable background = new ShapeDrawable();
Paint p = background.getPaint();
p.setStyle(FILL);
p.setColor(getResources().getColor(android.R.color.transparent));
p.setStyle(STROKE);
p.setStrokeWidth(1);
p.setColor(BLACK);
Drawable[] layers = new Drawable[] { clip, background };
setProgressDrawable(new LayerDrawable(layers));
setIndeterminate(false);
}
示例15: getBorderDrawable
import android.graphics.drawable.LayerDrawable; //導入依賴的package包/類
public static @Nullable
BorderDrawable getBorderDrawable(@NonNull View view){
Drawable drawable=view.getBackground();
if(drawable instanceof BorderDrawable){
return (BorderDrawable) drawable;
}
else if(drawable instanceof LayerDrawable){
if(((LayerDrawable) drawable).getNumberOfLayers()>1) {
Drawable innerDrawable=((LayerDrawable) drawable).getDrawable(0);
if(innerDrawable instanceof BorderDrawable){
return (BorderDrawable) innerDrawable;
}
}
}
return null;
}