Modifying Button Attributes

Earlier you customized the buttons in BeatBox by manually setting a style attribute in the res/layout/list_item_sound.xml file. If you have a more complex app, with buttons throughout many activities or fragments, setting a style attribute on each and every button does not scale well. You can take your theme a step further by defining a style in your theme for every button in your app.

Before adding a button style to your theme, remove the style attribute from list_item_sound.xml.

Listing 21.9  Be gone! We have a better way (res/layout/list_item_sound.xml)

<Button
    style="@style/BeatBoxButton.Strong" android:layout_width="match_parent" android:layout_height="120dp" android:onClick="@{() -> viewModel.onButtonClicked()}" ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.