I have an ActionBar
icon (the main one on the left, not an action item) that I would like to animate.
I am setting my ActionBar
's icon in my Activity
like this:
getSupportActionBar().setIcon(icon)
where icon
is a Drawable
produced by a library that converts a custom XML view into a bitmap. This XML view is a RelativeLayout
with a background image and a TextView
on top.
Today, when I have to update the TextView
I simply re-generate the icon
and call setIcon
again. Instead, I would like to get a hold of my TextView
and apply some animation effect on it, like fade-out and then fade-in after updating it (maybe never having to call setIcon
, just re-use the same one).
Not sure how to go about this. Can someone recommend an approach?
EDIT: trying this approach:
In MyActivity
:
Drawable myDrawable = new MyDrawable();
supportActionBar.setIcon(myDrawable);
and:
public class MyDrawable extends Drawable {
private Paint paint;
private RectF rect;
public MyDrawable() {
this.paint = new Paint();
this.rect = new RectF();
}
@Override
public void draw(Canvas canvas) {
paint.setARGB(255, 0, 255, 0);
paint.setStrokeWidth(2);
paint.setStyle(Paint.Style.FILL);
rect.right = 20f;
rect.bottom = 20f;
canvas.drawRoundRect(rect, 0.5f, 0.5f, paint);
}
@Override
public void setAlpha(int alpha) {
paint.setAlpha(alpha);
}
@Override
public void setColorFilter(ColorFilter cf) {
paint.setColorFilter(cf);
}
@Override
public int getOpacity() {
return PixelFormat.OPAQUE;
}
}
Nothing shows up. I verified that onDraw
gets called. Something suspicious to me is that canvas
has both height & width set to 1.