I'm pretty sure that you can't achieve that behaviour using only XML
files, but if you extend the TextView
class to a custom one that capitalises the first letter, then you should be able to use only XML
from this point on.
public class CapitalizeTextView extends TextView {
// Create here constructors matching super
@Override
public void setText(CharSequence text, BufferType type) {
StringBuilder builder = new StringBuilder(text);
builder.setCharAt(0, Character.toUpperCase(builder.charAt(0)));
super.setText(builder.toString(), type);
}
}
From this point on, you only have to use CapitalizeTextView
instead of TextView
and the first letter will be capitalised. It works from XML
or Java/Kotlin
.
<mobile.com.capitalize.CapitalizeTextView
......
android:text="not capital letter" />
textView.setText("not capital letter");