自定义VIew Onclick样式更改

时间:2016-08-19 08:39:00

标签: android android-layout

enter image description here

我有自定义动画播放/暂停按钮,当我按下它时会突出显示。如何删除按钮周围突出显示的灰色。 将背景设置为透明不起作用。

public static String decimalFormatter(Double number, int precision) {
        String pattern = "0.0";
        for (int i = 1; i < precision; i++) {
            pattern = pattern + "0";
        }
        DecimalFormat df = new DecimalFormat(pattern);
        df.setRoundingMode(RoundingMode.DOWN);
        return df.format(number);
}

}

public class PlayPauseMiniView extends FrameLayout {
private static final long PLAY_PAUSE_ANIMATION_DURATION = 200;

private final PlayPauseDrawable mDrawable;
private final Paint mPaint = new Paint();

private AnimatorSet mAnimatorSet;
private int mWidth;
private int mHeight;

public PlayPauseMiniView(Context context, AttributeSet attrs) {
    super(context, attrs);
    setWillNotDraw(false);
    mPaint.setAntiAlias(true);
    mPaint.setStyle(Paint.Style.FILL);
    mDrawable = new PlayPauseDrawable(context);
    mDrawable.setCallback(this);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    final int size = Math.min(getMeasuredWidth(), getMeasuredHeight());
    setMeasuredDimension(120, 120);
}

@Override
protected void onSizeChanged(final int w, final int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    mDrawable.setBounds(0, 0, w, h);
    mWidth = w;
    mHeight = h;

}


@Override
protected boolean verifyDrawable(Drawable who) {
    return who == mDrawable || super.verifyDrawable(who);
}

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    mDrawable.draw(canvas);
}

public void toggle() {
    if (mAnimatorSet != null) {
        mAnimatorSet.cancel();
    }

    mAnimatorSet = new AnimatorSet();
    final Animator pausePlayAnim = mDrawable.getPausePlayAnimator();
    mAnimatorSet.setInterpolator(new DecelerateInterpolator());
    mAnimatorSet.setDuration(PLAY_PAUSE_ANIMATION_DURATION);
    mAnimatorSet.playTogether(pausePlayAnim);
    mAnimatorSet.start();
}

}

2 个答案:

答案 0 :(得分:0)

您可以使用ImageView代替ImageButton

答案 1 :(得分:0)

您是否尝试过android:background =“@ null”?