Show a Fragment in FrameLayout without <fragment> element in layout editor?

739 Views Asked by At

I know that tools:layout can be used to show a fragment in <fragment> elements in the Android Studio's layout editor.

However, I want to add a fragment in a FrameLayout at runtime (so that I can change the fragment).

Similar questions found in SO like Question 1 and Question 2, but the answers in the pages cannot solve the problem exactly.

What I want to do is:

  • In an activity layout XML file
    • Insert a fragment (or fragment's layout XML) in a FrameLayout in the layout editor, without any <fragment> or <include> elements.
  • Something like tools:layout but not using <fragment> because it is not changeable. It is possible to use something like View.isInEditMode in code)
0

There are 0 best solutions below