I have a TextView. I'm trying to capitalize the first letter in every word.
Here's the TextView:
<TextView
android:text="TextView"
android:id="@+id/textView1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:textSize="30dip"
android:textStyle="bold"
android:layout_marginRight="5dip"
android:ellipsize="end"
android:capitalize="words">
</TextView>
Here's how I'm adding the text:
TextView titleView = (TextView) findViewById(R.id.textView1);
titleView.setText( section.replace("_", " ") );
Can I not add text dynamically and expect it to capitalize the words? Is another trait interfering with android:capitalize
? Is android:capitalize
broken?
Thanks for your replies.
If you are using an Android phone and Gboard, you can capitalize the first letter of any word with three touches. First, double-tap the word in question to highlight the word, then tap the shift button (the up arrow) on the keyboard to capitalize the first letter. Done!
Android should always be capitalized and is never plural or possessive. "Android", or anything confusingly similar to "Android", cannot be used in names of applications or accessory products, including phones, tablets, TVs, speakers, headphones, watches, and other devices. Instead, use "for Android".
If you're targeting API Level 14 and above, you should use
android:textAllCaps="true"
Otherwise, you'll have to implement this behavior yourself.
capitalize
is basically just a KeyListener
that you can set in XML, so it only applies to text input by the user. As the documentation states (emphasis mine):
If set, specifies that this TextView has a textual input method and should automatically capitalize what the user types.
There is a related question on how to capitalize the first letter of every word in Java which has some helpful answers.
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