Eko
Eko

Reputation: 1557

Generic layout button

I'm making a layout for a menu, and all my buttons have all the same height, the same width, the same background color, ... Is it possible to create a basic button, with all these informations and without the text and the onclick attribute, and then place it N times in the xml, where N is the number of items of my menu, and adding a text and an onclick attribute?

Upvotes: 0

Views: 404

Answers (1)

shalafi
shalafi

Reputation: 3996

What you are looking for is called styles.

You can define any style that sets any number of layout properties, then tell the view to use the style.

The styles.xml content looks like this (parent is optional)

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="CodeFont" parent="@android:style/TextAppearance.Medium">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:textColor">#00FF00</item>
        <item name="android:typeface">monospace</item>
    </style>
</resources>

And inside the layout you simply add it on the properties of the view like this:

   <TextView
    style="@style/CodeFont"
    android:text="@string/hello" />

Snipsets taken from the official documentation, which you can read for more details: http://developer.android.com/guide/topics/ui/themes.html

Upvotes: 1

Related Questions