Devansh Devansh - 3 months ago 13
Android Question

Using same button again

I'm creating an app to play audio. The layout is such that I have to give buttons with the same function, look etc in different places within the same activity.

I was wondering if there is a way by which I define the button (image button in this case) once and then just use the same definition in the layout file each time.

Answer

A possible solution would be to use the <include> tag. In other words:

  1. create a new xml file containing the imageButton with your custom styling
  2. include that layout in other layouts files

More info at: https://developer.android.com/training/improving-layouts/reusing-layouts.html

Comments