Tint / dim drawable on touch

前端 未结 8 1475
别跟我提以往
别跟我提以往 2021-01-31 11:24

The app I\'m currently working on uses a lot of ImageViews as buttons. The graphics on these buttons use the alpha channel to fade out the edges of the button and make them look

8条回答
  •  醉话见心
    2021-01-31 11:51

    You can combine StateListDrawable and LayerDrawable for this.

    public Drawable getDimmedDrawable(Drawable drawable) {
            Resources resources = getContext().getResources();
            StateListDrawable stateListDrawable = new StateListDrawable();
            LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{
                    drawable,
                    new ColorDrawable(resources.getColor(R.color.translucent_black))
            });
            stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, layerDrawable);
            stateListDrawable.addState(new int[]{android.R.attr.state_focused}, layerDrawable);
            stateListDrawable.addState(new int[]{android.R.attr.state_selected}, layerDrawable);
            stateListDrawable.addState(new int[]{}, drawable);
            return stateListDrawable;
    }
    

    I assume our colors.xml looks like this

    
    
        #80000000
    
    

提交回复
热议问题