0

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?

2 Answers 2

1

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"/>
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.