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.
- Insert a fragment (or fragment's layout XML) in a FrameLayout in the layout editor, without any
- Something like
tools:layout
but not using<fragment>
because it is not changeable. It is possible to use something likeView.isInEditMode
in code)