Java 安卓变暗背景

Java 安卓变暗背景,java,android,toolbar,statusbar,Java,Android,Toolbar,Statusbar,是否有人知道如何通过编程使视图的背景变暗,例如alertDialog或NavigationDrawer这样做?我需要背景与工具栏(1)和状态栏重叠,但是状态栏的图标应该可见(2)。在我的情况下,它不应该是一个对话框。例如,我必须使按钮或自定义视图周围的背景变暗 我一直在寻找这个问题的答案,但最终我找到了解决办法 我研究了代码“DialogPlus”库,找出了关键点 getWindow().getDecorView() final LayoutInflater inflater = (Layou

是否有人知道如何通过编程使
视图的背景变暗,例如
alertDialog
NavigationDrawer
这样做?我需要背景与
工具栏
(1)和
状态栏
重叠,但是
状态栏
的图标应该可见(2)。在我的情况下,它不应该是一个
对话框
。例如,我必须使
按钮
自定义视图
周围的背景变暗


我一直在寻找这个问题的答案,但最终我找到了解决办法

我研究了代码“DialogPlus”库,找出了关键点

getWindow().getDecorView()

final LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        final View background = inflater.inflate(R.layout.frame, null);
        final Animation a = AnimationUtils.loadAnimation(this, R.anim.in);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ViewGroup decorView = (ViewGroup) getWindow().getDecorView().findViewById(android.R.id.content);
                decorView.addView(background);
                background.startAnimation(a);
            }
        });
后台资源文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/black"
        android:alpha="0.5"></FrameLayout>
</LinearLayout>