You can use the java class SpannableString and Html languages to set the font color of a word in TextView to the specified color.
(1) SpannableString class
private void setText(TextView t){String text = t.getText().toString().trim();SpannableString span = new SpannableString(text);span.setSpan(new ForegroundColorSpan(Color.RED), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);t.setText(span);}
(2) html Markup Language
String html1 ="* Name:"; TextView. setText (Html. fromHtml (html1 ));
When lowercase letters are entered, the EditText edit box is automatically converted to uppercase letters. There are also multiple ways to set listening for an EditText object and call the setTransformationMethod () method of the EditText object.
(1) set listening for EditText
MEdtLicensePlateNumber. addTextChangedListener (new TextWatcher () {@ Overridepublic void onTextChanged (CharSequence s, int start, int before, int count) {// TODO Auto-generated method stubmEdtLicensePlateNumber. removeTextChangedListener (this); // cancel the mEdtLicensePlateNumber event. setText (s. toString (). toUpperCase (); // convert mEdtLicensePlateNumber. setSelection (s. toString (). length (); // reset the cursor position mEdtLicensePlateNumber. addTextChangedListener (this); // rebind licensePlateNumber = mEdtLicensePlateNumber. getText (). toString (). trim () ;}@ Overridepublic void beforeTextChanged (CharSequence s, int start, int count, int after) {// TODO Auto-generated method stub} @ Overridepublic void afterTextChanged (Editable s) {// TODO Auto-generated method stub }});
(2) Call the setTransformationMethod () method of the EditText object
public class InputLowerToUpper extends ReplacementTransformationMethod{@Overrideprotected char[] getOriginal() {char[] lower = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };return lower;}@Overrideprotected char[] getReplacement() {char[] upper = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };return upper;}}editext.setTransformationMethod(new InputLowerToUpper());