Reuse a group of buttons across several fragments

I have a fragment defined by the following xml file:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragment_example"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_example"/>

</RelativeLayout>

Now I would like to reuse the ImageButton (and other buttons I will add) in another fragment, ideally

I.e. the goal is to overlay the same set of buttons in different fragments.

Is there a way to define all buttons in a separate xml file and load them programmatically on fragment creation?

Upvotes: 0

Views: 160

Answers (1)

Chirag Jain
Chirag Jain

Reputation: 1612

Yes, You can.

Define all buttons in different xml say layout_buttons.xml

and add them in each fragment layout using

<include layout="@layout/layout_buttons" />

Upvotes: 1

Related Questions