Change the color of a color Android executable

I use EditText to get userInput, but the problem is that I want to change the font color at runtime, but in the same Edittext, because I can change the font type, but as the font changes, the font color changes for all editext, but I only need to change the color for text text.

And another problem is that when creating an edittext with a height greater than the "fillparent" property, I get the cursor in the middle, but I want it to be always at the top, i.e. on your marks..

Is there any other widget that will provide me with a solution for both problems?

+3
source share
1 answer

EditText :

editText.setGravity(Gravity.TOP);

EditText, Editable :

EditText editText = (EditText) findViewById(R.id.editview);
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);
+3

Source: https://habr.com/ru/post/1708880/


All Articles