Chapter 22 Styles and Themes
Style inheritance
Styles also support inheritance: A style can inherit and override attributes from another style.
Create a new style called BeatBoxButton.Strong that inherits from BeatBoxButton and also bolds the
text.
Listing 22.4 Inheriting from BeatBoxButton (res/values/styles.xml)
(While you could have added the android:textStyle attribute to the BeatBoxButton style directly,
you created BeatBoxButton.Strong to demonstrate style inheritance.)
The naming convention here is a little strange. When you name your style BeatBoxButton.Strong, you
are saying that your theme inherits attributes from BeatBoxButton.
There is also an alternative inheritance naming style. You can specify a parent when declaring the
style:
Stick with the BeatBoxButton.Strong style in BeatBox.
Update list_item_sound.xml to use your newer, stronger style.
Listing 22.5 Using a bolder style (res/layout/list_item_sound.xml)
<Button
style="@style/BeatBoxButton.Strong"
android:layout_width="match_parent"
android:layout_height="120dp"
android:onClick="@{() -> viewModel.onButtonClicked()}"
android:text="@{viewModel.title}"
tools:text="Sound name"/>