how to change text color without changing the the whole textview color





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I am trying to change the text color by simply clicking the button but when I click the button it changes the previously typed text color also. Means changes the whole text color. When I try to change color through Spannable then it changes the color of the selected part of the text but not for the text which I am going to type next. Is there a way where I can click the button and it does not change the whole text color but the color for which I type next. Thanks



enter image description here



here is what I know only



redtxt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
str.setSpan(new ForegroundColorSpan(Color.parseColor(txtColor)), selStart, selEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setTextColor(Color.parseColor("#d32f2f"));
}
});









share|improve this question

























  • Can u explain more about your requirement and also share your whole code like what is str and what is txtColor

    – Nilesh Rathod
    Nov 17 '18 at 4:26











  • Spannable str = text.getText(); int selStart = text.getSelectionStart(); int selEnd = text.getSelectionEnd(); ForegroundColorSpan styleSpans = text.getText().getSpans(selStart, selEnd, ForegroundColorSpan.class); and txtColor is the String which is the return value of button click for color.

    – S Shah
    Nov 17 '18 at 4:31













  • and what is str here can u please explain more about the same

    – Nilesh Rathod
    Nov 17 '18 at 4:34











  • str is Spannable name.

    – S Shah
    Nov 17 '18 at 4:35











  • @SShah , You need to implement Spannable String builder and onChangeText just append spanned string to Spannable String builder.

    – Anil Ravsaheb Ghodake
    Nov 17 '18 at 6:25




















0















I am trying to change the text color by simply clicking the button but when I click the button it changes the previously typed text color also. Means changes the whole text color. When I try to change color through Spannable then it changes the color of the selected part of the text but not for the text which I am going to type next. Is there a way where I can click the button and it does not change the whole text color but the color for which I type next. Thanks



enter image description here



here is what I know only



redtxt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
str.setSpan(new ForegroundColorSpan(Color.parseColor(txtColor)), selStart, selEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setTextColor(Color.parseColor("#d32f2f"));
}
});









share|improve this question

























  • Can u explain more about your requirement and also share your whole code like what is str and what is txtColor

    – Nilesh Rathod
    Nov 17 '18 at 4:26











  • Spannable str = text.getText(); int selStart = text.getSelectionStart(); int selEnd = text.getSelectionEnd(); ForegroundColorSpan styleSpans = text.getText().getSpans(selStart, selEnd, ForegroundColorSpan.class); and txtColor is the String which is the return value of button click for color.

    – S Shah
    Nov 17 '18 at 4:31













  • and what is str here can u please explain more about the same

    – Nilesh Rathod
    Nov 17 '18 at 4:34











  • str is Spannable name.

    – S Shah
    Nov 17 '18 at 4:35











  • @SShah , You need to implement Spannable String builder and onChangeText just append spanned string to Spannable String builder.

    – Anil Ravsaheb Ghodake
    Nov 17 '18 at 6:25
















0












0








0








I am trying to change the text color by simply clicking the button but when I click the button it changes the previously typed text color also. Means changes the whole text color. When I try to change color through Spannable then it changes the color of the selected part of the text but not for the text which I am going to type next. Is there a way where I can click the button and it does not change the whole text color but the color for which I type next. Thanks



enter image description here



here is what I know only



redtxt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
str.setSpan(new ForegroundColorSpan(Color.parseColor(txtColor)), selStart, selEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setTextColor(Color.parseColor("#d32f2f"));
}
});









share|improve this question
















I am trying to change the text color by simply clicking the button but when I click the button it changes the previously typed text color also. Means changes the whole text color. When I try to change color through Spannable then it changes the color of the selected part of the text but not for the text which I am going to type next. Is there a way where I can click the button and it does not change the whole text color but the color for which I type next. Thanks



enter image description here



here is what I know only



redtxt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
str.setSpan(new ForegroundColorSpan(Color.parseColor(txtColor)), selStart, selEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setTextColor(Color.parseColor("#d32f2f"));
}
});






java android eclipse






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 '18 at 3:14







S Shah

















asked Nov 17 '18 at 2:52









S ShahS Shah

156111




156111













  • Can u explain more about your requirement and also share your whole code like what is str and what is txtColor

    – Nilesh Rathod
    Nov 17 '18 at 4:26











  • Spannable str = text.getText(); int selStart = text.getSelectionStart(); int selEnd = text.getSelectionEnd(); ForegroundColorSpan styleSpans = text.getText().getSpans(selStart, selEnd, ForegroundColorSpan.class); and txtColor is the String which is the return value of button click for color.

    – S Shah
    Nov 17 '18 at 4:31













  • and what is str here can u please explain more about the same

    – Nilesh Rathod
    Nov 17 '18 at 4:34











  • str is Spannable name.

    – S Shah
    Nov 17 '18 at 4:35











  • @SShah , You need to implement Spannable String builder and onChangeText just append spanned string to Spannable String builder.

    – Anil Ravsaheb Ghodake
    Nov 17 '18 at 6:25





















  • Can u explain more about your requirement and also share your whole code like what is str and what is txtColor

    – Nilesh Rathod
    Nov 17 '18 at 4:26











  • Spannable str = text.getText(); int selStart = text.getSelectionStart(); int selEnd = text.getSelectionEnd(); ForegroundColorSpan styleSpans = text.getText().getSpans(selStart, selEnd, ForegroundColorSpan.class); and txtColor is the String which is the return value of button click for color.

    – S Shah
    Nov 17 '18 at 4:31













  • and what is str here can u please explain more about the same

    – Nilesh Rathod
    Nov 17 '18 at 4:34











  • str is Spannable name.

    – S Shah
    Nov 17 '18 at 4:35











  • @SShah , You need to implement Spannable String builder and onChangeText just append spanned string to Spannable String builder.

    – Anil Ravsaheb Ghodake
    Nov 17 '18 at 6:25



















Can u explain more about your requirement and also share your whole code like what is str and what is txtColor

– Nilesh Rathod
Nov 17 '18 at 4:26





Can u explain more about your requirement and also share your whole code like what is str and what is txtColor

– Nilesh Rathod
Nov 17 '18 at 4:26













Spannable str = text.getText(); int selStart = text.getSelectionStart(); int selEnd = text.getSelectionEnd(); ForegroundColorSpan styleSpans = text.getText().getSpans(selStart, selEnd, ForegroundColorSpan.class); and txtColor is the String which is the return value of button click for color.

– S Shah
Nov 17 '18 at 4:31







Spannable str = text.getText(); int selStart = text.getSelectionStart(); int selEnd = text.getSelectionEnd(); ForegroundColorSpan styleSpans = text.getText().getSpans(selStart, selEnd, ForegroundColorSpan.class); and txtColor is the String which is the return value of button click for color.

– S Shah
Nov 17 '18 at 4:31















and what is str here can u please explain more about the same

– Nilesh Rathod
Nov 17 '18 at 4:34





and what is str here can u please explain more about the same

– Nilesh Rathod
Nov 17 '18 at 4:34













str is Spannable name.

– S Shah
Nov 17 '18 at 4:35





str is Spannable name.

– S Shah
Nov 17 '18 at 4:35













@SShah , You need to implement Spannable String builder and onChangeText just append spanned string to Spannable String builder.

– Anil Ravsaheb Ghodake
Nov 17 '18 at 6:25







@SShah , You need to implement Spannable String builder and onChangeText just append spanned string to Spannable String builder.

– Anil Ravsaheb Ghodake
Nov 17 '18 at 6:25














3 Answers
3






active

oldest

votes


















0














get your whole text into Spannable like



Spannable text = edittext.getText();


After that just do.



if (edittext.getText().length() != 0){
text.setSpan(new ForegroundColorSpan(YOUR_COLOR), selection_start, selection_end, 34);
}





share|improve this answer


























  • It partially works but it does not work when I directly go to the next line then text color set to default. And also when I click near other span text it does not get its color from it.

    – S Shah
    Nov 17 '18 at 5:48






  • 1





    Then you need to code into TextWatcher() of Edittext. Apply above line every onTextChanged(). --->>>>> public void onTextChanged(CharSequence s1, final int start, final int before, final int count) { text.setSpan(new ForegroundColorSpan(color), start, start+1, 34); }

    – Harshil kakadiya
    Nov 17 '18 at 6:32













  • Now this works perfectly. Thanks. One more thing how can I get the color of adjacent text?? Let's suppose I typed previously in blue color and now I am typing in red color but when I want to add something in the blue text it takes that blue color from it and starts typing in the blue color in that area?

    – S Shah
    Nov 17 '18 at 17:46



















0














you can use SpannableString for example:



final SpannableString text = new SpannableString("Hello stackOverflow");
text.setSpan(new RelativeSizeSpan(1.5f), text.length() - "stackOverflow".length(), text.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(new ForegroundColorSpan(Color.RED), 3, text.length() - 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(text);





share|improve this answer


























  • I am using edit text which is Edittext text.

    – S Shah
    Nov 17 '18 at 4:34











  • I dont understand this part text.setSpan(new RelativeSizeSpan(1.5f), text.length() - "stackOverflow".length(), text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    – S Shah
    Nov 17 '18 at 4:44











  • or see some example in this link :medium.com/@programmerr47/…

    – saeedata
    Nov 17 '18 at 5:09



















0














You need to implement Spannable String builder(Global Object) and on onChangeText event just append spanned string to Spannable String builder.



    SpannableStringBuilder objSpannableStringBuilder;

edt.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
final SpannableString text = new SpannableString(s.toString());
text.setSpan(new ForegroundColorSpan(Color.RED), 3, text.length() - 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); objSpannableStringBuilder.append(text);
your_edit_text.setText(objSpannableStringBuilder);

}

@Override
public void afterTextChanged(Editable s) {

}
});





share|improve this answer


























  • what is meant by "your_edit_text(Spannable String) comes ere" this in your code?

    – S Shah
    Nov 17 '18 at 17:18











  • @SShah It means your text changed string (Variable CahrSequense s). I just edited answer. Check it now

    – Anil Ravsaheb Ghodake
    Nov 19 '18 at 4:29












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53347766%2fhow-to-change-text-color-without-changing-the-the-whole-textview-color%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














get your whole text into Spannable like



Spannable text = edittext.getText();


After that just do.



if (edittext.getText().length() != 0){
text.setSpan(new ForegroundColorSpan(YOUR_COLOR), selection_start, selection_end, 34);
}





share|improve this answer


























  • It partially works but it does not work when I directly go to the next line then text color set to default. And also when I click near other span text it does not get its color from it.

    – S Shah
    Nov 17 '18 at 5:48






  • 1





    Then you need to code into TextWatcher() of Edittext. Apply above line every onTextChanged(). --->>>>> public void onTextChanged(CharSequence s1, final int start, final int before, final int count) { text.setSpan(new ForegroundColorSpan(color), start, start+1, 34); }

    – Harshil kakadiya
    Nov 17 '18 at 6:32













  • Now this works perfectly. Thanks. One more thing how can I get the color of adjacent text?? Let's suppose I typed previously in blue color and now I am typing in red color but when I want to add something in the blue text it takes that blue color from it and starts typing in the blue color in that area?

    – S Shah
    Nov 17 '18 at 17:46
















0














get your whole text into Spannable like



Spannable text = edittext.getText();


After that just do.



if (edittext.getText().length() != 0){
text.setSpan(new ForegroundColorSpan(YOUR_COLOR), selection_start, selection_end, 34);
}





share|improve this answer


























  • It partially works but it does not work when I directly go to the next line then text color set to default. And also when I click near other span text it does not get its color from it.

    – S Shah
    Nov 17 '18 at 5:48






  • 1





    Then you need to code into TextWatcher() of Edittext. Apply above line every onTextChanged(). --->>>>> public void onTextChanged(CharSequence s1, final int start, final int before, final int count) { text.setSpan(new ForegroundColorSpan(color), start, start+1, 34); }

    – Harshil kakadiya
    Nov 17 '18 at 6:32













  • Now this works perfectly. Thanks. One more thing how can I get the color of adjacent text?? Let's suppose I typed previously in blue color and now I am typing in red color but when I want to add something in the blue text it takes that blue color from it and starts typing in the blue color in that area?

    – S Shah
    Nov 17 '18 at 17:46














0












0








0







get your whole text into Spannable like



Spannable text = edittext.getText();


After that just do.



if (edittext.getText().length() != 0){
text.setSpan(new ForegroundColorSpan(YOUR_COLOR), selection_start, selection_end, 34);
}





share|improve this answer















get your whole text into Spannable like



Spannable text = edittext.getText();


After that just do.



if (edittext.getText().length() != 0){
text.setSpan(new ForegroundColorSpan(YOUR_COLOR), selection_start, selection_end, 34);
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 17 '18 at 5:34

























answered Nov 17 '18 at 5:29









Harshil kakadiyaHarshil kakadiya

627




627













  • It partially works but it does not work when I directly go to the next line then text color set to default. And also when I click near other span text it does not get its color from it.

    – S Shah
    Nov 17 '18 at 5:48






  • 1





    Then you need to code into TextWatcher() of Edittext. Apply above line every onTextChanged(). --->>>>> public void onTextChanged(CharSequence s1, final int start, final int before, final int count) { text.setSpan(new ForegroundColorSpan(color), start, start+1, 34); }

    – Harshil kakadiya
    Nov 17 '18 at 6:32













  • Now this works perfectly. Thanks. One more thing how can I get the color of adjacent text?? Let's suppose I typed previously in blue color and now I am typing in red color but when I want to add something in the blue text it takes that blue color from it and starts typing in the blue color in that area?

    – S Shah
    Nov 17 '18 at 17:46



















  • It partially works but it does not work when I directly go to the next line then text color set to default. And also when I click near other span text it does not get its color from it.

    – S Shah
    Nov 17 '18 at 5:48






  • 1





    Then you need to code into TextWatcher() of Edittext. Apply above line every onTextChanged(). --->>>>> public void onTextChanged(CharSequence s1, final int start, final int before, final int count) { text.setSpan(new ForegroundColorSpan(color), start, start+1, 34); }

    – Harshil kakadiya
    Nov 17 '18 at 6:32













  • Now this works perfectly. Thanks. One more thing how can I get the color of adjacent text?? Let's suppose I typed previously in blue color and now I am typing in red color but when I want to add something in the blue text it takes that blue color from it and starts typing in the blue color in that area?

    – S Shah
    Nov 17 '18 at 17:46

















It partially works but it does not work when I directly go to the next line then text color set to default. And also when I click near other span text it does not get its color from it.

– S Shah
Nov 17 '18 at 5:48





It partially works but it does not work when I directly go to the next line then text color set to default. And also when I click near other span text it does not get its color from it.

– S Shah
Nov 17 '18 at 5:48




1




1





Then you need to code into TextWatcher() of Edittext. Apply above line every onTextChanged(). --->>>>> public void onTextChanged(CharSequence s1, final int start, final int before, final int count) { text.setSpan(new ForegroundColorSpan(color), start, start+1, 34); }

– Harshil kakadiya
Nov 17 '18 at 6:32







Then you need to code into TextWatcher() of Edittext. Apply above line every onTextChanged(). --->>>>> public void onTextChanged(CharSequence s1, final int start, final int before, final int count) { text.setSpan(new ForegroundColorSpan(color), start, start+1, 34); }

– Harshil kakadiya
Nov 17 '18 at 6:32















Now this works perfectly. Thanks. One more thing how can I get the color of adjacent text?? Let's suppose I typed previously in blue color and now I am typing in red color but when I want to add something in the blue text it takes that blue color from it and starts typing in the blue color in that area?

– S Shah
Nov 17 '18 at 17:46





Now this works perfectly. Thanks. One more thing how can I get the color of adjacent text?? Let's suppose I typed previously in blue color and now I am typing in red color but when I want to add something in the blue text it takes that blue color from it and starts typing in the blue color in that area?

– S Shah
Nov 17 '18 at 17:46













0














you can use SpannableString for example:



final SpannableString text = new SpannableString("Hello stackOverflow");
text.setSpan(new RelativeSizeSpan(1.5f), text.length() - "stackOverflow".length(), text.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(new ForegroundColorSpan(Color.RED), 3, text.length() - 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(text);





share|improve this answer


























  • I am using edit text which is Edittext text.

    – S Shah
    Nov 17 '18 at 4:34











  • I dont understand this part text.setSpan(new RelativeSizeSpan(1.5f), text.length() - "stackOverflow".length(), text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    – S Shah
    Nov 17 '18 at 4:44











  • or see some example in this link :medium.com/@programmerr47/…

    – saeedata
    Nov 17 '18 at 5:09
















0














you can use SpannableString for example:



final SpannableString text = new SpannableString("Hello stackOverflow");
text.setSpan(new RelativeSizeSpan(1.5f), text.length() - "stackOverflow".length(), text.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(new ForegroundColorSpan(Color.RED), 3, text.length() - 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(text);





share|improve this answer


























  • I am using edit text which is Edittext text.

    – S Shah
    Nov 17 '18 at 4:34











  • I dont understand this part text.setSpan(new RelativeSizeSpan(1.5f), text.length() - "stackOverflow".length(), text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    – S Shah
    Nov 17 '18 at 4:44











  • or see some example in this link :medium.com/@programmerr47/…

    – saeedata
    Nov 17 '18 at 5:09














0












0








0







you can use SpannableString for example:



final SpannableString text = new SpannableString("Hello stackOverflow");
text.setSpan(new RelativeSizeSpan(1.5f), text.length() - "stackOverflow".length(), text.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(new ForegroundColorSpan(Color.RED), 3, text.length() - 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(text);





share|improve this answer















you can use SpannableString for example:



final SpannableString text = new SpannableString("Hello stackOverflow");
text.setSpan(new RelativeSizeSpan(1.5f), text.length() - "stackOverflow".length(), text.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(new ForegroundColorSpan(Color.RED), 3, text.length() - 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(text);






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 17 '18 at 10:39

























answered Nov 17 '18 at 4:25









saeedatasaeedata

44137




44137













  • I am using edit text which is Edittext text.

    – S Shah
    Nov 17 '18 at 4:34











  • I dont understand this part text.setSpan(new RelativeSizeSpan(1.5f), text.length() - "stackOverflow".length(), text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    – S Shah
    Nov 17 '18 at 4:44











  • or see some example in this link :medium.com/@programmerr47/…

    – saeedata
    Nov 17 '18 at 5:09



















  • I am using edit text which is Edittext text.

    – S Shah
    Nov 17 '18 at 4:34











  • I dont understand this part text.setSpan(new RelativeSizeSpan(1.5f), text.length() - "stackOverflow".length(), text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    – S Shah
    Nov 17 '18 at 4:44











  • or see some example in this link :medium.com/@programmerr47/…

    – saeedata
    Nov 17 '18 at 5:09

















I am using edit text which is Edittext text.

– S Shah
Nov 17 '18 at 4:34





I am using edit text which is Edittext text.

– S Shah
Nov 17 '18 at 4:34













I dont understand this part text.setSpan(new RelativeSizeSpan(1.5f), text.length() - "stackOverflow".length(), text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

– S Shah
Nov 17 '18 at 4:44





I dont understand this part text.setSpan(new RelativeSizeSpan(1.5f), text.length() - "stackOverflow".length(), text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

– S Shah
Nov 17 '18 at 4:44













or see some example in this link :medium.com/@programmerr47/…

– saeedata
Nov 17 '18 at 5:09





or see some example in this link :medium.com/@programmerr47/…

– saeedata
Nov 17 '18 at 5:09











0














You need to implement Spannable String builder(Global Object) and on onChangeText event just append spanned string to Spannable String builder.



    SpannableStringBuilder objSpannableStringBuilder;

edt.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
final SpannableString text = new SpannableString(s.toString());
text.setSpan(new ForegroundColorSpan(Color.RED), 3, text.length() - 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); objSpannableStringBuilder.append(text);
your_edit_text.setText(objSpannableStringBuilder);

}

@Override
public void afterTextChanged(Editable s) {

}
});





share|improve this answer


























  • what is meant by "your_edit_text(Spannable String) comes ere" this in your code?

    – S Shah
    Nov 17 '18 at 17:18











  • @SShah It means your text changed string (Variable CahrSequense s). I just edited answer. Check it now

    – Anil Ravsaheb Ghodake
    Nov 19 '18 at 4:29
















0














You need to implement Spannable String builder(Global Object) and on onChangeText event just append spanned string to Spannable String builder.



    SpannableStringBuilder objSpannableStringBuilder;

edt.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
final SpannableString text = new SpannableString(s.toString());
text.setSpan(new ForegroundColorSpan(Color.RED), 3, text.length() - 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); objSpannableStringBuilder.append(text);
your_edit_text.setText(objSpannableStringBuilder);

}

@Override
public void afterTextChanged(Editable s) {

}
});





share|improve this answer


























  • what is meant by "your_edit_text(Spannable String) comes ere" this in your code?

    – S Shah
    Nov 17 '18 at 17:18











  • @SShah It means your text changed string (Variable CahrSequense s). I just edited answer. Check it now

    – Anil Ravsaheb Ghodake
    Nov 19 '18 at 4:29














0












0








0







You need to implement Spannable String builder(Global Object) and on onChangeText event just append spanned string to Spannable String builder.



    SpannableStringBuilder objSpannableStringBuilder;

edt.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
final SpannableString text = new SpannableString(s.toString());
text.setSpan(new ForegroundColorSpan(Color.RED), 3, text.length() - 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); objSpannableStringBuilder.append(text);
your_edit_text.setText(objSpannableStringBuilder);

}

@Override
public void afterTextChanged(Editable s) {

}
});





share|improve this answer















You need to implement Spannable String builder(Global Object) and on onChangeText event just append spanned string to Spannable String builder.



    SpannableStringBuilder objSpannableStringBuilder;

edt.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
final SpannableString text = new SpannableString(s.toString());
text.setSpan(new ForegroundColorSpan(Color.RED), 3, text.length() - 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); objSpannableStringBuilder.append(text);
your_edit_text.setText(objSpannableStringBuilder);

}

@Override
public void afterTextChanged(Editable s) {

}
});






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 19 '18 at 4:33

























answered Nov 17 '18 at 6:37









Anil Ravsaheb GhodakeAnil Ravsaheb Ghodake

94011937




94011937













  • what is meant by "your_edit_text(Spannable String) comes ere" this in your code?

    – S Shah
    Nov 17 '18 at 17:18











  • @SShah It means your text changed string (Variable CahrSequense s). I just edited answer. Check it now

    – Anil Ravsaheb Ghodake
    Nov 19 '18 at 4:29



















  • what is meant by "your_edit_text(Spannable String) comes ere" this in your code?

    – S Shah
    Nov 17 '18 at 17:18











  • @SShah It means your text changed string (Variable CahrSequense s). I just edited answer. Check it now

    – Anil Ravsaheb Ghodake
    Nov 19 '18 at 4:29

















what is meant by "your_edit_text(Spannable String) comes ere" this in your code?

– S Shah
Nov 17 '18 at 17:18





what is meant by "your_edit_text(Spannable String) comes ere" this in your code?

– S Shah
Nov 17 '18 at 17:18













@SShah It means your text changed string (Variable CahrSequense s). I just edited answer. Check it now

– Anil Ravsaheb Ghodake
Nov 19 '18 at 4:29





@SShah It means your text changed string (Variable CahrSequense s). I just edited answer. Check it now

– Anil Ravsaheb Ghodake
Nov 19 '18 at 4:29


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53347766%2fhow-to-change-text-color-without-changing-the-the-whole-textview-color%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python