活动中的透明圆圈



我有这样的活动

<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>

和Java代码是

@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));
}

此活动使用对话框主题,因此整个屏幕将为70-80%透明的灰色。我需要一个中心的完整透明圆,以便从中清楚地显示出其背后的活动。我该如何实现?

您可能对portduff.mode感兴趣。它可用于设置不同的传输模式以重叠视图。XOR属性可用于在原本全屏的布局中戳一个圆形孔,以使下面的内容可见。

https://developer.android.com/reference/android/graphics/porterduff.mode.html

最新更新