【问题标题】:Android darken backgroundAndroid使背景变暗
【发布时间】:2016-03-01 12:39:42
【问题描述】:

有谁知道如何以编程方式使View's 背景变暗,例如alertDialogNavigationDrawer 这样做?我需要背景与ToolBar (1) 和StatusBar 重叠,但StatusBar 的图标应该是可见的(2)。就我而言,它不应该是dialog。例如,我必须使ButtonCustomView 周围的背景变暗。

Example Image

【问题讨论】:

    标签: java android toolbar statusbar


    【解决方案1】:

    我一直在寻找这个问题的答案,但终于找到了解决方案。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-17
      • 2017-03-07
      • 2019-06-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多