LoginSignup
2
2

More than 5 years have passed since last update.

Material Component LibraryのMaterialButtonのtextAllCapsをテーマで変更する

Posted at

AppCompatButton同様、MaterialButtonもデフォルトでは textAllCaps="true"で全て大文字で表示されます。

AppCompatButtonの場合は、以下のようにテーマを指定すれば小文字にすることができました。

<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
    <item name="buttonStyle">@style/AppButton</item>
</style>

<style name="AppButton" parent="Widget.AppCompat.Button">
    <item name="android:textAllCaps">false</item>
</style>

MaterialButtonの場合は、指定する属性が少し変わるので注意が必要です。
具体的には、materialButtonStyle という新しい属性を指定します。

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    <!-- buttonStyleではなくmaterialButtonStyleを指定すること -->
    <item name="materialButtonStyle">@style/AppButton</item>
</style>

<style name="AppButton" parent="Widget.MaterialComponents.Button">
    <!-- MaterialComponentで定義された属性を指定するのでandroid:は不要 -->
    <item name="textAllCaps">false</item>
</style>

以上です。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2