A.J.
A.J.

Reputation: 1550

How can I reuse this Android button?

I have a Button that I am using 13 times in my Android application's main.xml file. I would like to have the XML for it defined once, so that I can make changes in one place instead of 13. Each of the 13 instances needs to have its own ID, though. What should I do to simplify my XML? I've tried using <include> but it hasn't worked for me. I must have been doing something wrong. I'd appreciate it if anyone could show me how to do it correctly. Thanks.

Here's the XML for the button that I'd like to reuse:

<Button
  android:width="70dp" 
  android:layout_marginLeft="10dp"
  android:layout_marginRight="10dp" />

Upvotes: 7

Views: 3695

Answers (1)

Macarse
Macarse

Reputation: 93143

You should use Styles and Themes for that sort of things.

Upvotes: 10

Related Questions