Material Components: MaterialTextViewでlineHeightがTextAppearanceから指定出来るようになりました

従来のTextView(AppCompatTextView)では、lineHeightの指定をTextAppearanceから出来ませんでした。

それが、material-component 1.1.0-alpha08にMaterialTextViewが爆誕し、lineHeightがTextAppearanceから指定出来るようになりました🎉

使い方

まずはstyleを定義します。

<style name="TextAppearance.LineHeight">
  <item name="lineHeight">20sp</item>
</style>

次に、TextViewから指定します。

<TextView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="テスト"
  android:textAppearance="@style/TextAppearance.LineHeight" />

これで完了です😃

MaterialTextViewをXMLから直接指定してもいいのですが、AppCompatActivityを使っていれば、自動的にMaterialTextViewがinflateされるようになっています。 詳しくはMaterialComponentsViewInflater.javaをご覧下さい。

まとめ

Written by
あんどろいどでぃべろっぱぁー🍎