71
65

More than 5 years have passed since last update.

Android LollipopでButtonのTextが大文字(textAllCaps)なるの、仕様です

Posted at

自分のアプリをLollipopが入った端末で見た時、ある違いに気づきませんでしたか?
そう、ボタンの文字が英文字の時は大文字になっているんです。
ioschedのアプリで見てみると、こんな感じ。

Lollipop

スクリーンショット 2014-12-09 11.40.12.png

4系

スクリーンショット 2014-12-09 12.14.10.png

対応

マテリアルデザインガイドには明確に記述されていないのですが,英文字ボタンは全て大文字になっています。これは仕様のようです。

API 21のButtonのデザインをたどるとstyleで大文字(textAllCaps)が設定されています。

/sdk/platforms/android-21/data/res/values/styles_material.xml
    <style name="TextAppearance.Material.Button">
        <item name="textSize">@dimen/text_size_button_material</item>
        <item name="fontFamily">@string/font_family_button_material</item>
        <item name="textAllCaps">true</item>
        <item name="textColor">?attr/textColorPrimary</item>
    </style>

なので、もし英文字を使ったボタンを小文字にしたいという要件がある場合、

  • style.xmlでButtonのスタイルを定義してあげる
  • ButtonをaddViewのようにプログラム上で生成する際はデフォルト(styles_material.xml)が適用されてしまうようなので、意図的にsetAllCapsを指定してあげる
button
Button button = new Button(this.getActivity());
button.setText(test.getLabel());
button.setAllCaps(false);
layout.addView(button);

などの対応が必要そうです。

71
65
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
71
65