Declare Fragment in Xml

  • In xml file, we have to use the tag to create the fragment.
  • This element has an attribute called android:name ; here we have to pass the name of that class which extends Fragment class.
  • The another attribute android:id is used to define the unique id for the fragment.
  • The demo example is shown below:
  • <fragment android:name="name of class which extends Fragment class"
    android:id="id of the fragment">
    </fragment>