AndroidのButtonでアルファベットテキストが全部大文字になる


はじめに

Androidを実装していて困ったのが、Buttonのテキストです。
英語で記述したテキストが全て大文字になってしまうのです。

大文字小文字を区別したいのに...地味に困ります。

対策

大文字小文字を区別したい時の解決策は、レイアウトxmlでandroid:textAllCaps="false"と指定してあげることです。
ボタンテキストは大文字固定がデフォルトになっているようです。

  • 修正前
activity_main.xml
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="hoge" />
  • 修正後
activity_main.xml
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="hoge"
    android:textAllCaps="false" /> //textAllCapsを指定する

もちろん、コードを書いて指定することもできます。

MainActivity.java
Button button = findViewById(R.id.button);
button.setAllCaps(false);