How to get Activity's content view?

前端 未结 8 771
一向
一向 2020-11-27 09:22

What method should I call to know if an Activity has its contentView (once the method setContentView() has been called)?

8条回答
  •  萌比男神i
    2020-11-27 09:57

    There is no "isContentViewSet" method. You may put some dummy requestWindowFeature call into try/catch block before setContentView like this:

    try {
      requestWindowFeature(Window.FEATURE_CONTEXT_MENU);
      setContentView(...)
    } catch (AndroidRuntimeException e) {
      // do smth or nothing
    }
    

    If content view was already set, requestWindowFeature will throw an exception.

提交回复
热议问题