简体   繁体   中英

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

Am using this in fragment page

 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));
            }

Try this

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);
        }

and remove this android:fitsSystemWindows=”true” from XML

Create a Custom class

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));
            }

        }


}

Then Call in onCreateView section.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM