Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning text color to text in EditText

Tags:

How do I assign a different color to text in EditText by extending it?

like image 794
Chaitanya Avatar asked Apr 20 '12 07:04

Chaitanya


People also ask

How do you change text color on edit?

This example demonstrate about how to change line color in EditText. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How do I change text color in XML?

In XML, we can set a text color by the textColor attribute, like android:textColor="#FF0000" .


2 Answers

you can change the text color by adding android:textColor like this:

<EditText     android:id="@+id/editText1"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:textColor="#f00" /> 
like image 138
C. Leung Avatar answered Sep 25 '22 14:09

C. Leung


use spans:

TextView textView = (TextView)findViewById(R.id.mytextview01); Spannable WordtoSpan = new SpannableString("partial colored text");         WordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE), 2, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText(WordtoSpan); 
like image 39
Buda Gavril Avatar answered Sep 25 '22 14:09

Buda Gavril