0
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Android のフォントスタイルで迷いたくない

Last updated at Posted at 2016-09-18

Overview

フォントは styles.xml に切り出した方がいいというのは知っていたが、いつも自分で定義していた
android-best-practices

MaterialDesign で既に定義されているものがあるので利用すると「ここのフォントサイズはどれにしよう」なんていう迷いが減ってよかった
MaterialDesign Typograpy-styles

dimens.xml

日本語は Dense scripts の箇所を参考に設定
他言語対応する場合は dimens.xml を言語ごとに設定したらいいですね

dimens.xml
    <dimen name="font_size_display4">112sp</dimen>
    <dimen name="font_size_display3">56sp</dimen>
    <dimen name="font_size_display2">45sp</dimen>
    <dimen name="font_size_display1">34sp</dimen>
    <dimen name="font_size_headline">24sp</dimen>
    <dimen name="font_size_title">21sp</dimen>
    <dimen name="font_size_subheading">17sp</dimen>
    <dimen name="font_size_body2">15sp</dimen>
    <dimen name="font_size_body1">15sp</dimen>
    <dimen name="font_size_caption">13sp</dimen>
    <dimen name="font_size_button">15sp</dimen>

styles_text_view.xml

styles_text_view.xml
<resources>

    <style name="Display4">
        <item name="android:textSize">@dimen/font_size_display4</item>
        <item name="android:fontFamily">sans-serif-light</item>
    </style>

    <style name="Display3">
        <item name="android:textSize">@dimen/font_size_display3</item>
        <item name="android:fontFamily">sans-serif</item>
    </style>

    <style name="Display2">
        <item name="android:textSize">@dimen/font_size_display2</item>
        <item name="android:fontFamily">sans-serif</item>
    </style>

    <style name="Display1">
        <item name="android:textSize">@dimen/font_size_display1</item>
        <item name="android:fontFamily">sans-serif</item>
    </style>

    <style name="Headline">
        <item name="android:textSize">@dimen/font_size_headline</item>
        <item name="android:fontFamily">sans-serif</item>
    </style>

    <style name="Title">
        <item name="android:textSize">@dimen/font_size_title</item>
        <item name="android:fontFamily">sans-serif-medium</item>
        <item name="android:textStyle">bold</item>
    </style>

    <style name="Subheading">
        <item name="android:textSize">@dimen/font_size_subheading</item>
        <item name="android:fontFamily">sans-serif</item>
    </style>

    <style name="Body2">
        <item name="android:textSize">@dimen/font_size_body2</item>
        <item name="android:fontFamily">sans-serif-medium</item>
        <item name="android:textStyle">bold</item>
    </style>

    <style name="Body1">
        <item name="android:textSize">@dimen/font_size_body1</item>
        <item name="android:fontFamily">sans-serif</item>
    </style>

    <style name="Caption">
        <item name="android:textSize">@dimen/font_size_caption</item>
        <item name="android:fontFamily">sans-serif</item>
    </style>

    <style name="Button">
        <item name="android:textSize">@dimen/font_size_button</item>
        <item name="android:fontFamily">sans-serif-medium</item>
        <item name="android:textStyle">bold</item>
    </style>

</resources>

0
6
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
0
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?