View v; v.getBackground().setColorFilter(Color.parseColor("#00ff00"), PorterDuff.Mode.DARKEN);
@Override public Animator onDisappear(ViewGroup sceneRoot, View view, TransitionValues startValues, TransitionValues endValues) { if (view == null || view.getBackground() == null) return null; return ObjectAnimator.ofInt(view.getBackground(), ViewUtils.DRAWABLE_ALPHA, 0); } }
@Override public Animator onAppear(ViewGroup sceneRoot, View view, TransitionValues startValues, TransitionValues endValues) { if (view == null || view.getBackground() == null) return null; Drawable background = view.getBackground(); background.setAlpha(0); return ObjectAnimator.ofInt(background, ViewUtils.DRAWABLE_ALPHA, 0, 255); }
/** * Unbind all drawables to avoid memory leaks. * Link: http://stackoverflow.com/a/6779164/1590502 * * @param view */ private void unbindDrawables(View view) { if (view.getBackground() != null) { view.getBackground().setCallback(null); } if (view instanceof ViewGroup) { for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) { unbindDrawables(((ViewGroup) view).getChildAt(i)); } ((ViewGroup) view).removeAllViews(); } }
private static boolean hasOpaqueBackground(View v) { final Drawable bg = v.getBackground(); return bg != null && bg.getOpacity() == PixelFormat.OPAQUE; }
private Drawable getBackground(View v){ Drawable background = v.getBackground(); if(background == null) return null; if(background instanceof RippleDrawable) return ((RippleDrawable)background).getBackgroundDrawable(); return background; }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public boolean onTouch(View v, MotionEvent event) { v .findViewById(R.id.row_content) .getBackground() .setHotspot(event.getX(), event.getY()); return(false); } });
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public boolean onTouch(View v, MotionEvent event) { v .findViewById(R.id.row_content) .getBackground() .setHotspot(event.getX(), event.getY()); return(false); } });
public boolean onTouchEvent(View v, MotionEvent event){ Drawable background = v.getBackground(); return background != null && background instanceof RippleDrawable && ((RippleDrawable) background).onTouch(v, event); }
@Override public void setPrimaryColors(@ColorInt int ... colors) { if (colors.length > 0) { final View thisView = this; if (!(thisView.getBackground() instanceof BitmapDrawable) && mPrimaryColor == null) { setPrimaryColor(colors[0]); mPrimaryColor = null; } if (mAccentColor == null) { if (colors.length > 1) { setAccentColor(colors[1]); // } else { // setAccentColor(colors[0] == 0xffffffff ? 0xff666666 : 0xffffffff); } mAccentColor = null; } } }
@Implementation protected void draw(android.graphics.Canvas canvas) { Drawable background = realView.getBackground(); if (background != null) { ShadowCanvas shadowCanvas = Shadow.extract(canvas); shadowCanvas.appendDescription("background:"); background.draw(canvas); } }
private static void unsetViewBackground(View view, ViewNodeInfo viewNodeInfo) { final Reference<? extends Drawable> backgroundReference = viewNodeInfo.getBackground(); final Drawable drawable = view.getBackground(); if (backgroundReference != null) { setBackgroundCompat(view, null); Reference.release(view.getContext(), drawable, (Reference<Drawable>) backgroundReference); } }
public void setBackgroundColor(int color){ this.backgroundColor = color; if(isEnabled()) beforeBackground = backgroundColor; LayerDrawable layer = (LayerDrawable) progressView.getBackground(); GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground); shape.setColor(color); super.setBackgroundColor(makePressColor()); }
@Test public void shouldClearBackgroundResource() throws Exception { view.setBackgroundResource(R.drawable.an_image); view.setBackgroundResource(0); assertThat(view.getBackground()).isEqualTo(null); }
@Test public void getBackground_shouldReturnNullIfNoBackgroundHasBeenSet() throws Exception { assertThat(view.getBackground()).isNull(); }
@Test public void shouldRecordBackgroundDrawable() { Drawable drawable = new BitmapDrawable(BitmapFactory.decodeFile("some/fake/file")); view.setBackgroundDrawable(drawable); assertThat(view.getBackground()).isSameAs(drawable); assertThat(ShadowView.visualize(view)).isEqualTo("background:\nBitmap for file:some/fake/file"); }
@Test public void shouldSetBackgroundColor() { int red = 0xffff0000; view.setBackgroundColor(red); ColorDrawable background = (ColorDrawable) view.getBackground(); assertThat(background.getColor()).isEqualTo(red); }
@Test public void shouldRecordBackgroundColor() { int[] colors = {R.color.black, R.color.clear, R.color.white}; for (int color : colors) { view.setBackgroundColor(color); ColorDrawable drawable = (ColorDrawable) view.getBackground(); assertThat(drawable.getColor()).isEqualTo(color); } }
public void start() { final View containerView = SwipeableViewHolderUtils.getSwipeableContainerView(mSwipingItem); ViewCompat.animate(containerView).cancel(); mRecyclerView.addItemDecoration(this); mStartTime = System.currentTimeMillis(); mTranslationY = (int) (mSwipingItem.itemView.getTranslationY() + 0.5f); mSwipeBackgroundDrawable = mSwipingItem.itemView.getBackground(); postInvalidateOnAnimation(); notifyDelayed(NOTIFY_REMOVAL_EFFECT_PHASE_1, mRemoveAnimationDuration); }
@Test public void shouldSetBackgroundResource() throws Exception { view.setBackgroundResource(R.drawable.an_image); assertThat(shadowOf((BitmapDrawable) view.getBackground()).getCreatedFromResId()) .isEqualTo(R.drawable.an_image); }