折叠时透明StatusBar

时间:2017-10-27 18:04:48

标签: android android-layout android-collapsingtoolbarlayout

我有三个工作状态栏。但是当 module tb(); reg clk1, clk2, clk3; initial begin $monitor($time,, "clk1 = %b; clk2 = %b, clk3 = %b", clk1, clk2, clk3); clk1 = 1'b0; clk2 = 1'b0; clk3 = 1'b0; #100 $finish; end always @* #5 clk1 = ~clk1; always @* #5 clk2 <= ~clk2; always @(clk3) clk3 <= #5 ~clk3; endmodule 折叠时,状态栏仍然是透明的 我希望状态栏在折叠时具有CollapsingToolbar颜色。

如何检测状态栏是否已折叠并删除透明度?

打印 - 扩展:

enter image description here

打印 - 折叠:

enter image description here

XML代码:

PrimaryDark

1 个答案:

答案 0 :(得分:0)

试试这个

AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.app_bar_layout_edit_profile);
        appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            boolean isShow = false;
            int scrollRange = -1;

            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                if (scrollRange == -1) {
                    scrollRange = appBarLayout.getTotalScrollRange();
                }
                if (scrollRange + verticalOffset == 0) {       
                      Window window = activity.getWindow();
                      window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

                      window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                      window.setStatusBarColor(activity.getResources().getColor(R.color.primary_color));


                    isShow = true;
                } else if (isShow) {
                    collapsingToolbarLayout.setTitle(" ");
                    isShow = false;
                    Window w =PerfilEmpresaActivity.this.getWindow(); 
                    w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATU‌​S, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                }
            }
        });