android.graphics.drawable.LayerDrawable#findDrawableByLayerId()源码实例Demo

下面列出了android.graphics.drawable.LayerDrawable#findDrawableByLayerId() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: RetailStore   文件: BaseActivity.java
public void setBadgeCount(Context context, LayerDrawable icon, int count) {

        MenuCounterDrawable badge;

        // Reuse drawable if possible
        Drawable reuse = icon.findDrawableByLayerId(R.id.ic_badge);
        if (reuse != null && reuse instanceof MenuCounterDrawable) {
            badge = (MenuCounterDrawable) reuse;
        } else {
            badge = new MenuCounterDrawable(context);
        }

        badge.setCount(count);
        icon.mutate();
        icon.setDrawableByLayerId(R.id.ic_badge, badge);
    }
 
源代码2 项目: AGIKSwipeButton   文件: Swipe_Button_View.java
void set_default(AttributeSet attrs, int defStyle) {
    inflate(getContext(), R.layout.sb_swipe_view, this);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        setBackground(ContextCompat.getDrawable(getContext(), R.drawable.sb_swipe_view_bg));
    } else {
        setBackgroundDrawable(ContextCompat.getDrawable(getContext(), R.drawable.sb_swipe_view_bg));
    }

    swipeTextView = findViewById(R.id.sb_text);
    swipe_button_controller = findViewById(R.id.sb_swipe);
    swipe_button_controller.setOnSeekBarChangeListener(this);
    swipe_bg_drawable = getBackground();
    swipeLayers = (LayerDrawable) swipe_button_controller.getThumb();
    thumb_bg_drawable = swipeLayers.findDrawableByLayerId(R.id.thumb_background);

    TypedArray attributes = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.SwipeButtonView,
            defStyle, defStyle);
    try {
        getAttributes(attributes);
    } finally {
        attributes.recycle();
    }
}
 
源代码3 项目: Noyze   文件: CmBatteryBar.java
/**
 * Updates the {@link ShapeDrawable} which displays the
 * color of the bar across the screen.
 */
public void setProgressDrawable(Drawable mDrawable, int mNewColor)
{
	if (mDrawable instanceof LayerDrawable &&
		getProgressDrawable() instanceof LayerDrawable)
	{
        final LayerDrawable mDraw = (LayerDrawable) getProgressDrawable();
        final ClipDrawable mShape = (ClipDrawable)
            mDraw.findDrawableByLayerId(android.R.id.progress);

        // Make sure we've got everything.
        if (mShape != null && mProgress != null &&
            mProgress.getPaint() != null)
        {
            mProgress.getPaint().setColor(mNewColor);
            final Rect mBounds = mDraw.getBounds();
            super.setProgressDrawable(mDraw);
            getProgressDrawable().setBounds(mBounds);
            return;
        }
	}
	
	super.setProgressDrawable(mDrawable);
}
 
源代码4 项目: MaterialDesignLibrary   文件: Switch.java
public void changeBackground() {
	if (eventCheck) {
		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);
	}
}
 
源代码5 项目: FlippableStackView   文件: ColorFragment.java
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_dummy, container, false);
    Bundle bdl = getArguments();

    mMainLayout = (FrameLayout) v.findViewById(R.id.main_layout);

    LayerDrawable bgDrawable = (LayerDrawable) mMainLayout.getBackground();
    GradientDrawable shape = (GradientDrawable) bgDrawable.findDrawableByLayerId(R.id.background_shape);
    shape.setColor(bdl.getInt(EXTRA_COLOR));

    return v;
}
 
源代码6 项目: meiShi   文件: ProgressBarDeterminate.java
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());
}
 
源代码7 项目: MaterialDesignLibrary   文件: CheckBox.java
public void changeBackground() {
	if (check) {
		setBackgroundResource(R.drawable.background_checkbox_check);
		LayerDrawable layer = (LayerDrawable) getBackground();
		GradientDrawable shape = (GradientDrawable) layer
				.findDrawableByLayerId(R.id.shape_bacground);
		shape.setColor(backgroundColor);
	} else {
		setBackgroundResource(R.drawable.background_checkbox_uncheck);
	}
}
 
源代码8 项目: react-native-GPay   文件: ReactSliderManager.java
@ReactProp(name = "maximumTrackTintColor", customType = "Color")
public void setMaximumTrackTintColor(ReactSlider view, Integer color) {
  LayerDrawable drawable = (LayerDrawable) view.getProgressDrawable().getCurrent();
  Drawable background = drawable.findDrawableByLayerId(android.R.id.background);
  if (color == null) {
    background.clearColorFilter();
  } else {
    background.setColorFilter(color, PorterDuff.Mode.SRC_IN);
  }
}
 
源代码9 项目: MoeGallery   文件: ProgressBarDeterminate.java
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());
}
 
源代码10 项目: MaterialDesignLibrary   文件: Card.java
public void setBackgroundColor(int color){
	this.backgroundColor = color;
	if(isEnabled())
		beforeBackground = backgroundColor;
	LayerDrawable layer = (LayerDrawable) getBackground();
	GradientDrawable shape =  (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
	shape.setColor(backgroundColor);
}
 
源代码11 项目: PhoneTutorial   文件: ButtonFloat.java
public ButtonFloat(Context context, AttributeSet attrs) {
	super(context, attrs);
	setBackgroundResource(R.drawable.background_button_float);
	sizeRadius = 28;
	setDefaultProperties();
	icon = new ImageView(context);
	if(drawableIcon != null) {
		try {
			icon.setBackground(drawableIcon);
		} catch (NoSuchMethodError e) {
			icon.setBackgroundDrawable(drawableIcon);
		}
	}
	RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(Utils.dpToPx(sizeIcon, getResources()),Utils.dpToPx(sizeIcon, getResources()));
	params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
	icon.setLayoutParams(params);
	addView(icon);		
	
	LayerDrawable layer = (LayerDrawable) getBackground();
	GradientDrawable shape =  (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
	shape.setColor(backgroundColor);
	
	post(new Runnable() {
		
		@Override
		public void run() {
			showPosition = ViewHelper.getY(ButtonFloat.this) - Utils.dpToPx(24, getResources());
			hidePosition = ViewHelper.getY(ButtonFloat.this) + getHeight() * 3;
			ViewHelper.setY(ButtonFloat.this, hidePosition);
		}
	});
	
}
 
private void updateProgressDrawable() {
    LayerDrawable progressBarDrawable = (LayerDrawable) getProgressDrawable();
    Drawable backgroundDrawable = progressBarDrawable.findDrawableByLayerId(android.R.id.background);
    Drawable progressDrawable = progressBarDrawable.findDrawableByLayerId(android.R.id.progress);
    TintUtil.tintDrawable(backgroundDrawable, mProgressBackgroundColor);
    TintUtil.tintDrawable(progressDrawable, mProgressColor);
}
 
源代码13 项目: atlas   文件: Button.java
public void setBackgroundColor(int color) {
	this.backgroundColor = color;
	if (isEnabled())
		beforeBackground = backgroundColor;
	try {
		LayerDrawable layer = (LayerDrawable) getBackground();
		GradientDrawable shape = (GradientDrawable) layer
				.findDrawableByLayerId(R.id.shape_bacground);
		shape.setColor(backgroundColor);
		rippleColor = makePressColor();
	} catch (Exception ex) {
		// Without bacground
	}
}
 
源代码14 项目: MeetMusic   文件: PlayActivity.java
private void setSeekBarBg(){
    try {
        int progressColor = CustomAttrValueUtil.getAttrColorValue(R.attr.colorPrimary,R.color.colorAccent,this);
        LayerDrawable layerDrawable = (LayerDrawable) seekBar.getProgressDrawable();
        ScaleDrawable scaleDrawable = (ScaleDrawable)layerDrawable.findDrawableByLayerId(android.R.id.progress);
        GradientDrawable drawable = (GradientDrawable) scaleDrawable.getDrawable();
        drawable.setColor(progressColor);
    }catch (Exception e){
        e.printStackTrace();
    }
}
 
源代码15 项目: MoeGallery   文件: CheckBox.java
private void changeBackgroundColor(int color) {
	LayerDrawable layer = (LayerDrawable) getBackground();
	GradientDrawable shape = (GradientDrawable) layer
			.findDrawableByLayerId(R.id.shape_bacground);
	shape.setColor(color);
}
 
源代码16 项目: PhoneTutorial   文件: TutorialActivity.java
private void setSmallBackground(View v){
	v.setBackgroundResource(R.drawable.background_small_indicator);
	LayerDrawable layer = (LayerDrawable) v.getBackground();
	GradientDrawable shape =  (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
	shape.setColor(colorIndicator);
}
 
private void setProgressBarColor(int dark) {
    LayerDrawable ld = (LayerDrawable) progressSlider.getProgressDrawable();
    ClipDrawable clipDrawable = (ClipDrawable) ld.findDrawableByLayerId(android.R.id.progress);
    clipDrawable.setColorFilter(dark, PorterDuff.Mode.SRC_IN);
}
 
源代码18 项目: DMAudioStreamer   文件: Slider.java
public void changeBackground() {
    setBackgroundResource(R.drawable.background_checkbox);
    LayerDrawable layer = (LayerDrawable) getBackground();
    GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
    shape.setColor(backgroundColor);
}
 
源代码19 项目: slideview   文件: SlideView.java
void init(AttributeSet attrs, int defStyle) {
    inflate(getContext(), R.layout.sv_slide_view, this);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        setBackground(ContextCompat.getDrawable(getContext(), R.drawable.sv_view_bg));
    } else {
        setBackgroundDrawable(ContextCompat.getDrawable(getContext(), R.drawable.sv_view_bg));
    }
    slideTextView = findViewById(R.id.sv_text);
    slider = findViewById(R.id.sv_slider);
    slider.setOnSeekBarChangeListener(this);
    slideBackground = getBackground();
    buttonLayers = (LayerDrawable) slider.getThumb();
    buttonBackground = buttonLayers.findDrawableByLayerId(R.id.buttonBackground);

    TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.SlideView,
            defStyle, defStyle);

    int strokeColor;
    float slideTextSize = spToPx(16, getContext());
    String slideText;
    boolean reverseSlide;
    ColorStateList sliderTextColor;
    try {
        animateSlideText = a.getBoolean(R.styleable.SlideView_sv_animateSlideText, true);
        reverseSlide = a.getBoolean(R.styleable.SlideView_sv_reverseSlide, false);
        strokeColor = a.getColor(R.styleable.SlideView_sv_strokeColor, ContextCompat.
                getColor(getContext(), R.color.sv_stroke_color_default));


        slideText = a.getString(R.styleable.SlideView_sv_slideText);
        sliderTextColor = a.getColorStateList(R.styleable.SlideView_sv_slideTextColor);

        slideTextSize = a.getDimension(R.styleable.SlideView_sv_slideTextSize, slideTextSize);
        slideTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, slideTextSize);

        setText(slideText);
        setTextColor(sliderTextColor == null ? slideTextView.getTextColors() : sliderTextColor);

        int buttonImageId = a.getResourceId(R.styleable.SlideView_sv_buttonImage, R.drawable.sv_ic_chevron_double_right);
        setButtonImage(ContextCompat.getDrawable(getContext(), buttonImageId));
        setButtonImageDisabled(ContextCompat.getDrawable(getContext(), a.getResourceId
                (R.styleable.SlideView_sv_buttonImageDisabled, buttonImageId)));

        setButtonBackgroundColor(a.getColorStateList(R.styleable.SlideView_sv_buttonBackgroundColor));
        setSlideBackgroundColor(a.getColorStateList(R.styleable.SlideView_sv_slideBackgroundColor));

        if (a.hasValue(R.styleable.SlideView_sv_strokeColor)) {
            Util.setDrawableStroke(slideBackground, strokeColor);
        }
        if (reverseSlide) {
            slider.setRotation(180);
            LayoutParams params = ((LayoutParams) slideTextView.getLayoutParams());
            params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0);
            params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                params.addRule(RelativeLayout.ALIGN_PARENT_END, 0);
                params.addRule(RelativeLayout.ALIGN_PARENT_START);
            }
            slideTextView.setLayoutParams(params);
        }
    } finally {
        a.recycle();
    }
}
 
源代码20 项目: PhoneTutorial   文件: ButtonFloat.java
public void setBackgroundColor(int color){
	this.backgroundColor = color;
	LayerDrawable layer = (LayerDrawable) getBackground();
	GradientDrawable shape =  (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
	shape.setColor(backgroundColor);
}