Change the Bar Status to transparent in a Fragment within an Activity

1

I have a Activity which has a theme for its Status Bar, but it has an influence on Fragment to which I want another color in the Status Bar.

Is there any way I can change the color of the Status Bar only when that Fragment is opened, and return to normal when it is closed?

    
asked by anonymous 27.07.2015 / 20:49

2 answers

2

You can change through the setStatusBarColor() method:

context.getWindow().setStatusBarColor(Color.TRANSPARENT);

Please note that this function is only available from API 21 ( Lollipop ), so check it before using it:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    context.getWindow().setStatusBarColor(Color.TRANSPARENT);
}
    
27.07.2015 / 23:39
0

With Status Bar , you mean the Actionbar / Toolbar ? If so, you can manually change (code) with:

ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#CCFF0000")));

In this way, when the Fragment is created you can get the Activity, from the Activity get the Fragment and change by color the Actionbar color.

EDIT:

I had misinterpreted your question. The answer from sicachester is correct.

    
27.07.2015 / 23:34