// try this way
1. custom class for set different color for different text.
public class ColorSpannable extends ClickableSpan {
private int color = -1;
private float fontSize = -1;
private boolean isUnderline = true;
/**
* Constructor
*/
public ColorSpannable() {
}
/**
* Constructor
*/
public ColorSpannable(int color) {
this.color = color;
}
/**
* Constructor
*/
public ColorSpannable(float fontSize) {
this.fontSize = fontSize;
}
/**
* Constructor
*/
public ColorSpannable(boolean isUnderline) {
this.isUnderline = isUnderline;
}
/**
* Constructor
*/
public ColorSpannable(int color, boolean isUnderline) {
this.isUnderline = isUnderline;
this.color = color;
}
/**
* Constructor
*/
public ColorSpannable(int color, float fontSize) {
this.color = color;
this.fontSize = fontSize;
}
/**
* Overrides methods
*/
@Override
public void updateDrawState(TextPaint ds) {
if (color != -1) {
ds.setColor(color);
}
if (fontSize > 0) {
ds.setTextSize(fontSize);
}
ds.setUnderlineText(isUnderline);
}
@Override
public void onClick(View widget) {
}
}
2. custom method for apply different color for different text.
public SpannableStringBuilder addClickablePart(String message,final ArrayList<String> changeTextList,ArrayList<String> changeTextColorList) {
String str = message;
SpannableStringBuilder ssb = new SpannableStringBuilder(Html.fromHtml(message));
for(int i=0;i<changeTextList.size();i++){
String colorHashValue;
if(changeTextColorList.size()>=i){
colorHashValue = changeTextColorList.get(i);
}else{
colorHashValue = "#ff0000";
}
ssb.setSpan(new ColorSpannable(Color.parseColor(colorHashValue), false) {
@Override
public void onClick(View widget) {
}
}, str.indexOf(changeTextList.get(i)), str.indexOf(changeTextList.get(i)) + changeTextList.get(i).length(), 0);
}
return ssb;
}
3. how to use it
AlertDialog.Builder builder = new AlertDialog.Builder(this);
ArrayList<String> textList = new ArrayList<String>();
ArrayList<String> textColorList = new ArrayList<String>();
textList.add("red");
textList.add("green");
textList.add("blue");
textList.add("yellow");
textList.add("pink");
textColorList.add("#ff0000");
textColorList.add("#008000");
textColorList.add("#0000ff");
textColorList.add("#ffff00");
textColorList.add("#ffc0cb");
builder.setTitle("Multiple color text Dialog").setMessage(addClickablePart("this my custom text red green blue yellow pink",textList,textColorList)).setCancelable(false).setNeutralButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog alert = builder.create();
alert.setCancelable(true);
alert.show();
here i gave you demo code you can also modify as per your requirement still any problem let me know will try to help.
사용자 정의 테마를 만드는 조회 의미한다. 나는 당신이 그렇게하지 않고도 그렇게 할 수 있다고 믿지 않습니다. –