Amir_P Amir_P - 1 year ago 101
Android Question

Transparent circle inside an activity

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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download