I am learning Android and the following is part of an assignment.
I need to write some text in an Android layout with the first letter in drop caps, like the following text:
I looked up the web and did not find many answers. Is there a style option or some property that I could use?
At the moment, I am thinking of the following options. Please suggest what is the best way to do such a thing
Any suggestions would be helpful.
You can add a nice decorative element to your document using a drop cap. While Google Docs doesn’t offer a drop-cap feature like Microsoft Word, you can still create one in just a few minutes. A drop cap is the first letter of a word in a paragraph or a block of text.
Following does not apply to TextView, but works with EditText; even then, it applies to the text entered from the keyboard, not the text loaded with setText(). To be more specific, it turns the Caps on in the keyboard, and the user can override this at her will. android:inputType="textCapSentences" or
Place your cursor at the beginning of the word in the paragraph or block of text where you want your drop cap to be. You can remove the first letter of the word either before or after you create the drop cap for it. Next, click Insert > Drawing from the menu and choose “New.”
A drop cap is the first letter of a word in a paragraph or a block of text. It’s an upper case letter that’s larger than the rest of the text and can stretch two or more lines. You’ll most often see a drop cap in a book, but it has its place in certain types of documents as well.
You can use a RelativeSizeSpan
.
final String someText = "A long time ago in a galaxy far, far away";
final SpannableString ss = new SpannableString(someText);
ss.setSpan(new RelativeSizeSpan(5f), 0, 1, 0);
There's a library written by Novoda in which you can add a DropCap
https://github.com/novoda/spikes/tree/master/drop-cap
Here's an image from the demo app:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With