userbb
userbb

Reputation: 1874

Xml for custom Button

I have many custom buttons in my layout xml. And each of that button has property i.e width. Can I create one xml for that custom button with defines width property?

Upvotes: 0

Views: 93

Answers (2)

Caleb Bramwell
Caleb Bramwell

Reputation: 1342

You can create a dimens resource and referance that from your button

xml resources file:

<resources>
<dimen name="my_dimen">10dip</dimen> </resources>

xml layout file:

<Button
android:layout_width="@dimen/my_dimen"/>

Upvotes: 1

hasanghaforian
hasanghaforian

Reputation: 14022

You can create Attribute Resources for your custom views(for example buttons).create a new file in your project "res/values" folder by selecting it and choosing "File", "New", "File". Enter "attrs.xml" as the file.Then declare-styleable for your view.Now you can use them in XML layout when add your view to layout.You can see more details here.

Upvotes: 0

Related Questions