chandan
chandan

Reputation: 11

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

Upvotes: 0

Views: 3794

Answers (2)

Goku
Goku

Reputation: 9692

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

Upvotes: 1

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75778

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

Upvotes: 0

Related Questions