Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1
Styles

Listing 22.3  Using a style (res/layout/list_item_sound.xml)


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


Run BeatBox and you will see that all of your buttons now have a dark blue background color
(Figure 22.2).


Figure 22.2  BeatBox with button styles


You can create a style for any set of attributes that you want to reuse in your application. Pretty handy.

Free download pdf