问题
For Lollipop+, I am trying to set the status bar translucent from a fragment. The calling activity’s layout contains a FrameLayout, the activity uses the SupportFragmentManager to replace the original fragment with the new fragment. Inside the new fragment’s onViewCreated I am using the ContextThemeWrapper to set the new theme. The theme contains several changes and changing the status bar to translucent is one of them. The other theme changes take effect, but the status bar maintains the color from the calling activity’s theme.
Note: If I set the calling activity's theme to the translucent action bar theme, both activity and fragments have translucent status bars, so its not a problem with the theme.
回答1:
In the fragment's onCreateView method, added :
getActivity().getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
getActivity().getWindow().setStatusBarColor(Color.TRANSPARENT );
Turns out the changing of theme wasn't necessary if one is just after a translucent status bar.
回答2:
1. Can you try to set setStatusBarColor
transparency programmatically
getWindow().setStatusBarColor(Color.TRANSPARENT);
2. Its achieve to add below line in your styles.xml
.
<item name="android:statusBarColor">@android:color/transparent</item>
来源:https://stackoverflow.com/questions/34011779/setting-translucent-status-bar-from-a-fragment