Java – Change font color when running Android

Change font color when running Android… here is a solution to the problem.

Change font color when running Android

I’m using EditText to get userInput but the problem is
Faced with the fact that I want to change the font color at runtime, but in
Same Edittext as I was able to change the font type, but when I do
The font color of the entire edited text will change, but I need to change it
The color of only specific text.

There is also a problem when used
The height exceeds the “fillparent” property of the cursor I get
The middle position, but I want it to always be at the top, i.e. in

Are there any other widgets available that can give me a solution
For these two questions?


The EditText widget can be controlled by gravity Chinese the alignment of the book:


To attach a markup object to the contents of an EditText, you can use the Editable interface:

EditText editText = (EditText) findViewById(;
SpannableStringBuilder builder = new SpannableStringBuilder();
builder.append("one red word");
builder.setSpan(new ForegroundColorSpan(Color.RED), 4, 7, Spanned.SPAN_COMPOSING);
editText.setText(builder, BufferType.EDITABLE);

Related Problems and Solutions