android 如何将片段页面中的状态栏颜色更改为透明

How to change a status bar color in a Fragment page as Transparent in android

我在 fragment 页面

中使用它
 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
                getActivity().getWindow().setStatusBarColor(getResources().getColor(R.color.transparant));
            }

创建Customclass

public class CommonStatusBarColor {


     public void StatusBarColor(Activity activity, String colorCode)
        {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
            {
                Window window =activity.getWindow();
                window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                window.setStatusBarColor(Color.parseColor(colorCode));
            }

        }


}

然后调用onCreateView部分。

 CommonStatusBarColor commonStatusBarColorObj =new CommonStatusBarColor();
 commonStatusBarColorObj.StatusBarColor(getActivity(),"#00ffffff"); // set your color

试试这个

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().setStatusBarColor(Color.TRANSPARENT);
        }

并从 XML

中删除此 android:fitsSystemWindows=”true”