Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android:capitalize not working

Tags:

java

android

xml

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.

like image 955
emachine Avatar asked Sep 27 '11 17:09

emachine


People also ask

How do you capitalize words on Android?

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!

Should Android capitalized?

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".


2 Answers

If you're targeting API Level 14 and above, you should use

android:textAllCaps="true"

Otherwise, you'll have to implement this behavior yourself.

like image 120
Nir Pear Avatar answered Oct 15 '22 12:10

Nir Pear


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.

like image 34
eldarerathis Avatar answered Oct 15 '22 12:10

eldarerathis