How do I assign a different color to text in EditText by extending it?
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.
In XML, we can set a text color by the textColor attribute, like android:textColor="#FF0000" .
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" />
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With