如何在布局中的任何视图上添加灰色叠加

FET*_*FET 0 android

我想知道如何为布局文件中的所有内容添加灰色覆盖,以便查看布局中的所有内容,但是启用了该灰色透明覆盖。

我试图将a View设置为backgroundlike #80000000,但是看起来这View 占用了所有空间(LinearLayout实际上我在使用a )。

相反,我希望此覆盖层覆盖所有其他视图,但仍然希望能够看到其背后的内容。

Sha*_*hav 5

达到效果的方法之一是使用<FrameLayout>容器作为根。您可以在其中添加当前布局以及带有背景的视图。在这里,view应该覆盖整个屏幕。因此,您的布局将类似于:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="match_parent"
         android:layout_height="match_parent">

    <!-- Your current layout here -->

    <!-- View to cover your screen -->
    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/black" />

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)