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.
Asked
Active
Viewed 1,890 times
0

Phantômaxx
- 37,901
- 21
- 84
- 115

Muhammad Noamany
- 52
- 9
-
You're going to need at least a customTextLayout, if not a custom TextView. That isn't any type of built in feature. – Gabe Sechan Jul 11 '17 at 18:18
-
See this [post](https://stackoverflow.com/questions/19030843/how-to-make-the-first-character-much-larger-than-other-in-a-textview), there is a good explanation. – J-Jamet Jul 11 '17 at 18:20
4 Answers
2
Please try this code snippet, this will help you.
String str = "sample text";
//Change first character to capital letter
String tempStr = str.substring(0, 1).toUpperCase() + str.substring(1);
//Change font size of the first character. You can change 2f as you want
SpannableString spannableString = new SpannableString(tempStr);
spannableString.setSpan(new RelativeSizeSpan(2f), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//Set the formatted text to text view
tvSample.setText(spannableString);

EKN
- 1,886
- 1
- 16
- 29
1
You can use this :
String upperString = myString.substring(0,1).toUpperCase() + myString.substring(1);
1
100% work
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 into 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>
4) In your java code just findItById and set Text.
Reference-> https://github.com/novoda/drop-cap

Sheharyar Ejaz
- 2,808
- 1
- 14
- 15
0
You can use one textView for character A and another textView for rest of text. i don't think is there any code to write like this because of alignment.

Akash Arora
- 71
- 1
- 14