AndroidにMaterial Designを導入したときに、何度もつまづいたので、メモ。
初めての導入
build.gradleに以下を記載します。
implementation 'com.google.android.material:material:1.3.0-alpha03'
Gradle Syncした後にMaterial Buttonを使ってみます。
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button"
...
/>
実行、そしてクラッシュ
このボタンがあるActivityを起動すると、以下のエラーで落ちました。
Error inflating class com.google.android.material.button.MaterialButton
解決方法
res/values/styles.xml
をMaterial Design用に変えないといけない。
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
↓
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
参考
https://qiita.com/susu_susu__/items/67f86582188ff28ad910
https://material.io/develop/android/docs/getting-started