Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I dim the backround view when a custom View is displayed

Tags:

android

layout

How can I dim my background when custom View is showing? In my Activity I have Relative Layout with some photo in background. When user do some action - FrameLayout appears in center of screen - and then I want make it to act like dialog - dim everything under framelayout.

How can I achieve that?

like image 878
Bandzio Avatar asked Sep 28 '11 14:09

Bandzio


1 Answers

add this view over it.. it ll help you..

public class TransparentPanel extends LinearLayout {
    private Paint innerPaint;

    public TransparentPanel(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public TransparentPanel(Context context) {
        super(context);
        init();
    }

    private void init() {
        innerPaint = new Paint();
        innerPaint.setARGB(180, 75, 75, 75);
    }

    public void setInnerPaint(Paint innerPaint) {
        this.innerPaint = innerPaint;
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {

        RectF drawRect = new RectF();
        drawRect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());

        canvas.drawRoundRect(drawRect, 5, 5, innerPaint);

        super.dispatchDraw(canvas);
    }
}
like image 58
Thiru Avatar answered Nov 07 '22 15:11

Thiru