【问题标题】:How can i change the colour of the status bar in the particular fragment?如何更改特定片段中状态栏的颜色?
【发布时间】:2016-10-14 09:21:59
【问题描述】:

我的问题是我想更改特定片段中状态栏的颜色。在所有其他片段中颜色应该相同。例如在所有片段中我的状态栏颜色是红色。但在特定片段中我想把它改成黑色。谁能告诉我该怎么做?

这是我的片段的 onCreateView 方法:-

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

【问题讨论】:

  • 最好的部分是使用主题。

标签: android android-fragments android-statusbar


【解决方案1】:
 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));

在片段的 onResume() 上编写这段代码,并在 onPause() 方法上恢复颜色,这样应用程序在其他片段中就会有旧的状态栏颜色。

【讨论】:

  • 这可行,但黑色会覆盖文本。有什么想法吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-05
  • 1970-01-01
  • 1970-01-01
  • 2016-07-06
相关资源
最近更新 更多