Android 如何更改特定片段中状态栏的颜色?
我的问题是我想更改特定片段中状态栏的颜色。在所有其他片段中,颜色应相同。例如,与所有片段一样,我的状态栏颜色为红色。但在特定片段中,我想将其更改为黑色。谁能告诉我怎么做 这是我的片段的onCreateView方法:-Android 如何更改特定片段中状态栏的颜色?,android,android-fragments,android-statusbar,Android,Android Fragments,Android Statusbar,我的问题是我想更改特定片段中状态栏的颜色。在所有其他片段中,颜色应相同。例如,与所有片段一样,我的状态栏颜色为红色。但在特定片段中,我想将其更改为黑色。谁能告诉我怎么做 这是我的片段的onCreateView方法:- @Override public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { final View v
@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
final View view = (View) inflater.inflate(R.layout.slide_user_image, container, false);
Window window = getActivity().getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(getActivity().getResources().getColor(R.color.black));
return view;
}
在片段的Resume()上编写此代码,并在onPause()方法上还原颜色,以便应用程序在其他片段中具有旧的statusbarcolor
在片段的Resume()上编写此代码,并在onPause()方法上还原颜色,以便应用程序在其他片段中具有旧的statusbarcolor。最好的部分是使用主题。最好的部分是使用主题。
Window window = getActivity().getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(getActivity().getResources().getColor(R.color.black));