【问题标题】:requestFeature() must be called before adding content in fragment class在片段类中添加内容之前必须调用 requestFeature()
【发布时间】:2015-07-08 16:20:45
【问题描述】:

我想使用:

getActivity().getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);

但得到这个错误:

在添加内容之前必须调用requestFeature()

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    getActivity().getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    View rootView = inflater.inflate(R.layout.cities, container, false);

    return rootView;
}

【问题讨论】:

    标签: android fragment


    【解决方案1】:

    这意味着您需要在将任何View 设置为Activity 之前请求所需的功能,即在Activity 中调用setContentView() 之前

    【讨论】:

      【解决方案2】:

      一旦您拨打了setContentView(),您就无法拨打requestFeature()

      【讨论】:

        【解决方案3】:

        在 Fragment 中设置 Activity 的属性不是一个好主意,不是吗?

        在 YourActivity.onCreate() 中执行。

        【讨论】:

          【解决方案4】:

          requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY); 必须在活动中的 super.onCreate 之前,而不是在 Fragment 中

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2011-05-14
            • 1970-01-01
            • 2014-11-21
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多