0

I have an activity like this

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    tools:context=".WaitingActivity">
</FrameLayout>

and the java code is

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_waiting);
    getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}

This activity is using dialog theme so whole screen will be 70-80% transparent gray. I need a full transparent circle in center so the activity behind it shows clearly from it. How can I achieve that?

Amir_P
  • 8,322
  • 5
  • 43
  • 92

1 Answers1

1

You may be interested in the PortDuff.Mode. It can be used to set different transfer modes for overlapping views. XOR property can be used to poke a circular hole in an otherwise fullscreen layout so that content beneath becomes visible.

https://developer.android.com/reference/android/graphics/PorterDuff.Mode.html

Siddharth Garg
  • 1,560
  • 14
  • 19
  • so i should create a custom view with the width and height i want to be transparent and then in onDraw method draw circle on canvas? this will create the hole on the background of my activity? – Amir_P Oct 02 '17 at 14:03
  • Yes. Pretty much. You might have to experiment with the Modes a little bit. I am not very confident which one would suit your needs. I guess it would depend on your layout and what you want to achieve. There are loads of good stackoverflow questions for this. (Much more reliable than me, I am afraid)... E.g. : https://stackoverflow.com/questions/19947835/android-canvas-draw-transparent-circle-on-image – Siddharth Garg Oct 02 '17 at 14:09
  • I had a use case of creating an overlay over my activites to act as a help overlay. Wanted to poke holes all over to highlight some items on the activity below. I researched on PorterDuff a little bit and it was perfect for my use case. But later we changed design and I never got to implement it. – Siddharth Garg Oct 02 '17 at 14:11
  • 1
    it's creating hole throw all views behind it but dialogs background stays. i will remove the dialog theme and make a transparent activity with a gray view as background and the custom view i made as hole in center. thanks a lot – Amir_P Oct 02 '17 at 14:16