Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
255 views
in Technique[技术] by (71.8m points)

Eszett (ß) in Android App (2)

I have a span like this:

 private SpannableStringBuilder spandex(List<String> ret, Boolean startDark) {
    SpannableStringBuilder spanBuilder = new SpannableStringBuilder();
    Spannable span = null;
    int color = 0;
    int startDarkMod = 0;
    if(startDark)
        startDarkMod = 1;
    for (String x : ret) {

        if ((ret.indexOf(x) + startDarkMod) % 2 > 0)
            color = WzTheme.NOT_HIGHLIGHTED_COLOR;
        else
            color = WzTheme.ALT_NOT_HIGHLIGHTED_COLOR;

        span = new SpannableString(x.toUpperCase());
        span.setSpan(new ForegroundColorSpan(color),
                0,
                x.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        spanBuilder.append(span);
    }

    return spanBuilder;
}


public static int NOT_HIGHLIGHTED_COLOR = Color.rgb(68, 68, 68);
public static int ALT_NOT_HIGHLIGHTED_COLOR = Color.rgb(110, 110, 110);

It produces light gray and dark grey code like this: screen shot galaxy5 activity

Then there is that bright white "T". It happens after every ? character, which, as the other thread mentioned, gets converted to SS when capitalized. I would prefer no capatalization of that char, but I can live with the conversion to SS. What I need to stop from happening is the big white "T". Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

ugh, this fixes it:

private String myUpperCase(String word) {
    word = word.replaceAll("?", "XXX");
    return word.toUpperCase().replaceAll("XXX", "?");
}  

so as you probably already know, the issue is that ? gets expanded to SS in java utf-8 toUpperCase() and that increases the length of the string in the span by one, but "x" (in my code above) is one char short (length) so i get the default white text.

i am happy with the fix.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...