Search code examples
javaandroidxmlandroid-layout

Capitalize and enlarge the first letter of TextView in android


How to make the first letter of a text in a textView large and capital using android studio like the one in the attached image.

this is the image


Solution

  • enter image description here

    This 100% works. Here are the steps:

    1. Use this library

      compile 'com.novoda:drop-cap:1.1.0'
      
    2. Define it in your layout

      <com.novoda.dropcap.DropCapView
        android:id="@+id/view_drop_cap"
        style="@style/DropCap"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/button1_detail" />
      
    3. Define it into your styles.xml

      <style name="DropCap">
        <item name="android:paddingLeft">@dimen/drop_cap_padding_left</item>
        <item name="android:paddingTop">@dimen/drop_cap_padding_top</item>
        <item name="android:paddingRight">@dimen/drop_cap_padding_right</item>
        <item name="android:paddingBottom">@dimen/drop_cap_padding_bottom</item>
        <item name="dropCapTextSize">@dimen/drop_cap_text</item>
        <item name="numberOfDropCaps">1</item>
        <item name="dropCapFontPath">fonts/SANS-SERIF_Cabin-Regular.otf</item>
        <item name="copyTextSize">@dimen/copy_text</item>
        <item name="copyFontPath">fonts/neuropolitical_rg.ttf</item>
        <item name="lineSpacingExtra">@dimen/drop_cap_linespacing_extra</item>
      </style>
      
    4. Define it in your dimens.xml

      <dimen name="drop_cap_padding_left">10dp</dimen>
      <dimen name="drop_cap_padding_top">10dp</dimen>
      <dimen name="drop_cap_padding_right">10dp</dimen>
      <dimen name="drop_cap_padding_bottom">10dp</dimen>
      <dimen name="drop_cap_text">64sp</dimen>
      <dimen name="copy_text">21sp</dimen>
      <dimen name="scroll_view_height">200dp</dimen>
      <dimen name="divider_height">1dp</dimen>
      <dimen name="drop_cap_linespacing_extra">0sp</dimen>
      
    5. In your Java code, just findItById() and set Text.

    Reference -> https://github.com/novoda/drop-cap